我试图做一些简单的编辑文本,但我的按钮不起作用......我有一个
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);
}
}