请帮我看看这个程序 这个错怎么改啊 请也说明下为什么会错的呢
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class JoptionPaneFrame extends JFrame
{
JPanel contentPane;
FlowLayout flowLayout1=new FlowLayout();
JButton jbutton1=new JButton();
JButton jbutton2=new JButton();
JButton jbutton3=new JButton();
JButton jbutton4=new JButton();
public JoptionPaneFrame()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
}
catch(Exception e)
{e.printStackTrace();}
}
private void jbInit() throws Exception
{
contentPane=(JPanel)this.getContentPane();
jbutton1.setText("Confirm Dialog");
jbutton1.addActionListener(new java.awt.event.ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton1_actionPerformed(this);}
});
contentPane.setLayout(flowLayout1);
this.setSize(498,98);
this.setTitle("JOptionPane Example");
jbutton2.setText("Input Dialog");
jbutton2.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton2_actionPerformed(this);}
});
jbutton3.setText("Option Dialog");
jbutton3.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton3_actionPerformed(this);}
});
jbutton4.setText("Message Dialog");
jbutton4.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton4_actionPerformed(this);}
});
contentPane.add(jbutton1,null);
contentPane.add(jbutton2,null);
contentPane.add(jbutton3,null);
contentPane.add(jbutton4,null);
}protected void processWindowEvent(WindowEvent we)
{
super.processWindowEvent(we);
if(we.getID()==WindowEvent.WINDOW_CLOSING)
System.exit(0);
}void jbutton1_actionPerformed(ActionEvent e)
{
JOptionPane.showConfirmDialog(this,"This is a test!","Confirm Dialog",JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE);}void jbutton2_actionPerformed(ActionEvent e)
{
String[] s={"a","b"};
JOptionPane.showInputDialog(this,"This is a test!Please input the value","Input Dialog",JOptionPane.INFORMATION_MESSAGE,null,s,"b");
}void jbutton3_actionPerformed(ActionEvent e)
{
String[] s={"a","b","c"};
JOptionPane.showOptionDialog(this,"Warning!This is a Test!","Option Dialog",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE,null,s,"c");
}void jbutton4_actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(this,"Error!\nThis is a Message Dialog test!","Message Dialog",JOptionPane.ERROR_MESSAGE);
}
}
错误信息:
E:\JAVA\练习\第九章\JoptionPaneFrame.java:31: 无法将 JoptionPaneFrame 中的 jbutton1_actionPerformed(java.awt.event.ActionEvent) 应用于 (<匿名 java.awt.event.ActionListener>)
{public void actionPerformed(ActionEvent ae){jbutton1_actionPerformed(this);}
^
E:\JAVA\练习\第九章\JoptionPaneFrame.java:39: 无法将 JoptionPaneFrame 中的 jbutton2_actionPerformed(java.awt.event.ActionEvent) 应用于 (<匿名 java.awt.event.ActionListener>)
{public void actionPerformed(ActionEvent ae){jbutton2_actionPerformed(this);}
^
E:\JAVA\练习\第九章\JoptionPaneFrame.java:44: 无法将 JoptionPaneFrame 中的 jbutton3_actionPerformed(java.awt.event.ActionEvent) 应用于 (<匿名 java.awt.event.ActionListener>)
{public void actionPerformed(ActionEvent ae){jbutton3_actionPerformed(this);}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class JoptionPaneFrame extends JFrame
{
JPanel contentPane;
FlowLayout flowLayout1=new FlowLayout();
JButton jbutton1=new JButton();
JButton jbutton2=new JButton();
JButton jbutton3=new JButton();
JButton jbutton4=new JButton();
public JoptionPaneFrame()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
}
catch(Exception e)
{e.printStackTrace();}
}
private void jbInit() throws Exception
{
contentPane=(JPanel)this.getContentPane();
jbutton1.setText("Confirm Dialog");
jbutton1.addActionListener(new java.awt.event.ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton1_actionPerformed(this);}
});
contentPane.setLayout(flowLayout1);
this.setSize(498,98);
this.setTitle("JOptionPane Example");
jbutton2.setText("Input Dialog");
jbutton2.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton2_actionPerformed(this);}
});
jbutton3.setText("Option Dialog");
jbutton3.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton3_actionPerformed(this);}
});
jbutton4.setText("Message Dialog");
jbutton4.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton4_actionPerformed(this);}
});
contentPane.add(jbutton1,null);
contentPane.add(jbutton2,null);
contentPane.add(jbutton3,null);
contentPane.add(jbutton4,null);
}protected void processWindowEvent(WindowEvent we)
{
super.processWindowEvent(we);
if(we.getID()==WindowEvent.WINDOW_CLOSING)
System.exit(0);
}void jbutton1_actionPerformed(ActionEvent e)
{
JOptionPane.showConfirmDialog(this,"This is a test!","Confirm Dialog",JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE);}void jbutton2_actionPerformed(ActionEvent e)
{
String[] s={"a","b"};
JOptionPane.showInputDialog(this,"This is a test!Please input the value","Input Dialog",JOptionPane.INFORMATION_MESSAGE,null,s,"b");
}void jbutton3_actionPerformed(ActionEvent e)
{
String[] s={"a","b","c"};
JOptionPane.showOptionDialog(this,"Warning!This is a Test!","Option Dialog",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE,null,s,"c");
}void jbutton4_actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(this,"Error!\nThis is a Message Dialog test!","Message Dialog",JOptionPane.ERROR_MESSAGE);
}
}
错误信息:
E:\JAVA\练习\第九章\JoptionPaneFrame.java:31: 无法将 JoptionPaneFrame 中的 jbutton1_actionPerformed(java.awt.event.ActionEvent) 应用于 (<匿名 java.awt.event.ActionListener>)
{public void actionPerformed(ActionEvent ae){jbutton1_actionPerformed(this);}
^
E:\JAVA\练习\第九章\JoptionPaneFrame.java:39: 无法将 JoptionPaneFrame 中的 jbutton2_actionPerformed(java.awt.event.ActionEvent) 应用于 (<匿名 java.awt.event.ActionListener>)
{public void actionPerformed(ActionEvent ae){jbutton2_actionPerformed(this);}
^
E:\JAVA\练习\第九章\JoptionPaneFrame.java:44: 无法将 JoptionPaneFrame 中的 jbutton3_actionPerformed(java.awt.event.ActionEvent) 应用于 (<匿名 java.awt.event.ActionListener>)
{public void actionPerformed(ActionEvent ae){jbutton3_actionPerformed(this);}
解决方法:
把其中的this换成JoptionPaneFrame.this, 其他几个地方也作相同的更换.
jbutton4.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton4_actionPerformed(this);}
});
------------------------------------------------------------------------------
jbutton4.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton4_actionPerformed(JoptionPaneFrame.this);}
});
{
JPanel contentPane;
FlowLayout flowLayout1=new FlowLayout();
JButton jbutton1=new JButton();
JButton jbutton2=new JButton();
JButton jbutton3=new JButton();
JButton jbutton4=new JButton(); public JoptionPaneFrame()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
}
catch(Exception e)
{e.printStackTrace();}
}
private void jbInit() throws Exception
{
contentPane=(JPanel)this.getContentPane();
jbutton1.setText("Confirm Dialog");
jbutton1.addActionListener(new java.awt.event.ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton1_actionPerformed(ae);}
});
contentPane.setLayout(flowLayout1);
this.setSize(498,98);
this.setTitle("JOptionPane Example"); jbutton2.setText("Input Dialog");
jbutton2.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton2_actionPerformed(ae);} //改这里
}); jbutton3.setText("Option Dialog");
jbutton3.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton3_actionPerformed(ae);}
}); jbutton4.setText("Message Dialog");
jbutton4.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent ae){jbutton4_actionPerformed(ae);}
}); contentPane.add(jbutton1,null);
contentPane.add(jbutton2,null);
contentPane.add(jbutton3,null);
contentPane.add(jbutton4,null); } protected void processWindowEvent(WindowEvent we)
{
super.processWindowEvent(we);
if(we.getID()==WindowEvent.WINDOW_CLOSING)
System.exit(0);
} void jbutton1_actionPerformed(ActionEvent e)
{
JOptionPane.showConfirmDialog(this,"This is a test!","Confirm Dialog",JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE); } void jbutton2_actionPerformed(ActionEvent e)
{
String[] s={"a","b"};
JOptionPane.showInputDialog(this,"This is a test!Please input the value","Input Dialog",JOptionPane.INFORMATION_MESSAGE,null,s,"b"); } void jbutton3_actionPerformed(ActionEvent e)
{
String[] s={"a","b","c"};
JOptionPane.showOptionDialog(this,"Warning!This is a Test!","Option Dialog",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE,null,s,"c"); } void jbutton4_actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(this,"Error!\nThis is a Message Dialog test!","Message Dialog",JOptionPane.ERROR_MESSAGE);
}
}
一看你的代码就知道是jbuilder写的.其实你可以试下使用eclipse 的swt designer插件.它的事件添加方式更适合我们.个人觉得.jb自动完成的事件处理方式太伤心了