首页上一页 1 下一页尾页 1 条记录 1/1页
13章swing按钮事件问题
发表在Java图书答疑
2011-05-14
是否精华
是
否
版块置顶:
是
否
请问那个swing按钮事件里的actionlistener怎么总是标红报错啊,我按书上和视频里的输入都不行
import java.awt.*;
import javax.swing.*;
public class mj extends JDialog{
public mj(mj frame){
super(new mf(),"这是一个对话框",true);
Container c=getContentPane();
c.add(new JLabel("对话框"));
setBounds(120,120,100,100);
}
}
class mf extends JFrame{
public mf(){
Container c=getContentPane();
JLabel jl=new JLabel("主窗体");
c.add(jl);
JButton jb=new JButton("按钮");
jb.setBounds(10, 10, 100, 21);
[font color=#FF0000]jb.addActionListener(new ActionListener(){
public void actionPerformed(actionEvent arg0){
new mj(mf.this).setVisible(true);
[/font] }
});
c.add(jb);
}
public static void main(String arg[]){
new mf();
}
}
import java.awt.*;
import javax.swing.*;
public class mj extends JDialog{
public mj(mj frame){
super(new mf(),"这是一个对话框",true);
Container c=getContentPane();
c.add(new JLabel("对话框"));
setBounds(120,120,100,100);
}
}
class mf extends JFrame{
public mf(){
Container c=getContentPane();
JLabel jl=new JLabel("主窗体");
c.add(jl);
JButton jb=new JButton("按钮");
jb.setBounds(10, 10, 100, 21);
[font color=#FF0000]jb.addActionListener(new ActionListener(){
public void actionPerformed(actionEvent arg0){
new mj(mf.this).setVisible(true);
[/font] }
});
c.add(jb);
}
public static void main(String arg[]){
new mf();
}
}