Java and button events?
-
So im trying to make a java application and i want to make a button the does something when it is clicked, i cant figure out how... here is my code so far: import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class MattisCoolClassMain { /** * @param args */ public static void main(String[] args) { JFrame mainframe = new JFrame(); mainframe.setDefaultCloseOperation(J… mainframe.setVisible(true); mainframe.setBounds(0,0,300,300); mainframe.setTitle("Hello Friend"); JPanel mainpanel = new JPanel(); mainframe.add(mainpanel); mainpanel.setBounds(0,0,300,300); mainpanel.setBackground(Color.CYAN); JLabel mainlabel = new JLabel(); mainpanel.add(mainlabel); mainlabel.setBounds(150,150,100,100)… mainlabel.setText("RAJ BUT EXPELS GREEN PISS"); JButton mainbutton = new JButton(); mainpanel.add(mainbutton); mainbutton.setBounds(200,200,100,100… mainbutton.setText("Click me for spam"); // TODO Auto-generated method stub } } So i looked up online, and i saw that i need to use a "action listener", i don't know how i am supposed to get that? Do make a new class? A new Method? -please note i am a great programmer, but i have never messed with java... so please dont use big terms xD thank you very much for any advice, tips, or answers you may be able to give me :-)
-
Answer:
You need an action listener to catch what action is performed. Here is a quick reference: http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html
Matthew at Yahoo! Answers Visit the source
Related Q & A:
- How do you pause a program until a button is pressed in JAVA?Best solution by Stack Overflow
- How to Implement Gateway Service something similar to Oracle API gateway Using Java and Java based Open Source frameworks only?Best solution by Quora
- How to change color of radio button when checked radio button?Best solution by Stack Overflow
- How to draggable button background color to apply another button background?Best solution by Stack Overflow
- Difference between Java 2 and Java 6?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.