テキストを簡単に編集できるようにしようとしていますが、ボタンが機能していません...
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals(submit.getActionCommand())){
JOptionPane.showMessageDialog(null,"you tried to submit");
}
}
メソッドが動作していないようです。助けてください?
public class Editor implements ActionListener{
static JFrame frame = new JFrame();
static Container contentPane = frame.getContentPane();
static int line;
static JTextField lineNumber = new JTextField("Line number here");
static JTextField editField = new JTextField("Data here", 48);
static JButton submit = new JButton("Save");
public Editor(){
frame.setTitle("Editor (Lnull)");
frame.setSize(400,600);
frame.setVisible(true);
}
public Editor(String title){
frame.setTitle(title);
frame.setSize(400,600);
frame.setVisible(true);
}
public Editor(String title, int width, int height){
frame.setTitle(title);
frame.setSize(width, height);
frame.setVisible(true);
}
@SuppressWarnings("static-access")
public void setLine(int line){
this.line = line;
}
public void changeTitle(String title){
frame.setTitle(title);
}
public static void addComponent(Component thing){
contentPane.add(thing);
frame.repaint();
}
public static void setContentsOfFrame(Container cont){
frame.setContentPane(contentPane);
}
public static void setAction(JButton comp, String action){
comp.setActionCommand(action);
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals(submit.getActionCommand())){
JOptionPane.showMessageDialog(null,"you tried to submit");
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Editor editor = new Editor();
addComponent(editField);
editField.setBounds(0,0,300,50);
addComponent(submit);
submit.setBounds(300,0,100,50);
submit.setActionCommand("submit");
frame.setLayout(null);
setContentsOfFrame(contentPane);
}
}