急求!!!这个java程序怎么添加按钮监听器?
//LABEL在PANEL中importjava.awt.*;importjavax.swing.*;publicclassjiamian3extendsJFrame{J...
//LABEL在PANEL中
import java.awt.*;
import javax.swing.*;
public class jiamian3 extends JFrame{
JPanel jp1,jp2,jp3,jp4;
JButton jb1,jb2;
JLabel jl1;
public static void main(String[] args)
{
jiamian3 b=new jiamian3();
}
public jiamian3()
{
//主界面周三最终板
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jp4=new JPanel();
jp4.setLayout(new GridLayout(3,1));
jb1=new JButton("分数线查询");
jb2=new JButton("专业信息查询");
jl1=new JLabel("欢迎使用招生信息查询系统");
jp1.add(jb1);
jp1.add(jb2);
jp2.add(jl1);
jp4.add(jp3);
jp4.add(jp2);
jp4.add(jp1);//空panel 3 林业大学 2 按钮1
jl1.setForeground(Color.blue);
jl1.setFont(new Font("BOLD",Font.BOLD,34));
this.add(jp4,BorderLayout.CENTER);
this.setTitle("招生信息查询系统");
setSize(600,400);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
} 展开
import java.awt.*;
import javax.swing.*;
public class jiamian3 extends JFrame{
JPanel jp1,jp2,jp3,jp4;
JButton jb1,jb2;
JLabel jl1;
public static void main(String[] args)
{
jiamian3 b=new jiamian3();
}
public jiamian3()
{
//主界面周三最终板
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jp4=new JPanel();
jp4.setLayout(new GridLayout(3,1));
jb1=new JButton("分数线查询");
jb2=new JButton("专业信息查询");
jl1=new JLabel("欢迎使用招生信息查询系统");
jp1.add(jb1);
jp1.add(jb2);
jp2.add(jl1);
jp4.add(jp3);
jp4.add(jp2);
jp4.add(jp1);//空panel 3 林业大学 2 按钮1
jl1.setForeground(Color.blue);
jl1.setFont(new Font("BOLD",Font.BOLD,34));
this.add(jp4,BorderLayout.CENTER);
this.setTitle("招生信息查询系统");
setSize(600,400);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
} 展开
1个回答
推荐于2016-10-09
展开全部
//LABEL在PANEL中
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class jiamian3 extends JFrame {
JPanel jp1, jp2, jp3, jp4;
JButton jb1, jb2;
JLabel jl1;
public static void main(String[] args) {
jiamian3 b = new jiamian3();
}
public jiamian3() {
// 主界面周三最终板
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
jp4 = new JPanel();
jp4.setLayout(new GridLayout(3, 1));
jb1 = new JButton("分数线查询");
jb2 = new JButton("专业信息查询");
jl1 = new JLabel("欢迎使用招生信息查询系统");
jp1.add(jb1);
jp1.add(jb2);
jp2.add(jl1);
jp4.add(jp3);
jp4.add(jp2);
jp4.add(jp1);// 空panel 3 林业大学 2 按钮1
jl1.setForeground(Color.blue);
jl1.setFont(new Font("BOLD", Font.BOLD, 34));
this.add(jp4, BorderLayout.CENTER);
this.setTitle("招生信息查询系统");
setSize(600, 400);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
jb1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JDialog jd = new JDialog();
jd.setBounds(20,20,150,100);
jd.setTitle("打开窗口");
jd.setVisible(true);
}
});
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询