this helped me a little bit.
but i need to help me with implementing 9(3,3)buttons
the firs and the last row will have initial
label.and i want to move the labels to the
closest free button.(its submission is December 19/2011)
Dear friend
i have a similar problem to your example, but i have to put actionlistener in a different class outside of the the main class.
to be more clear my problem is like that:
import javax.swing.*;
import java.awt.event.*;
public class ChangeButtonLabel{
JButton button;
public static void main(String[] args){
ChangeButtonLabel cl = new ChangeButtonLabel();
}
public ChangeButtonLabel(){
JFrame frame = new JFrame("Change JButton Lebel");
button = new JButton("Click Me");
button.addActionListener(new MyAction());
frame.add(button);
frame.setSize(400, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MyAction implements ActionListener{
public void actionPerformed(ActionEvent e){
String text = (String)e.getActionCommand();
if (text.equals("Click Me")){
button.setText("Roseindia.net");
}
else{
button.setText("Click Me");
}
}
}
I get an error that buttons is not cannot be resolved, any help wold be available.
hitsegalem December 10, 2011 at 2:42 PM
this helped me a little bit. but i need to help me with implementing 9(3,3)buttons the firs and the last row will have initial label.and i want to move the labels to the closest free button.(its submission is December 19/2011)
Question for this codeAntonio January 30, 2012 at 12:16 AM
Dear friend i have a similar problem to your example, but i have to put actionlistener in a different class outside of the the main class. to be more clear my problem is like that: import javax.swing.*; import java.awt.event.*; public class ChangeButtonLabel{ JButton button; public static void main(String[] args){ ChangeButtonLabel cl = new ChangeButtonLabel(); } public ChangeButtonLabel(){ JFrame frame = new JFrame("Change JButton Lebel"); button = new JButton("Click Me"); button.addActionListener(new MyAction()); frame.add(button); frame.setSize(400, 400); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class MyAction implements ActionListener{ public void actionPerformed(ActionEvent e){ String text = (String)e.getActionCommand(); if (text.equals("Click Me")){ button.setText("Roseindia.net"); } else{ button.setText("Click Me"); } } } I get an error that buttons is not cannot be resolved, any help wold be available.
javaankit September 12, 2012 at 7:00 PM
when i click on any rectangle then co-ordinates changed....
super examplesathish March 25, 2013 at 11:54 PM
java super example
Post your Comment