java eclipse中如何实现点击主窗口sShell中的按钮打开另外一个子窗口sShell
2个回答
展开全部
import java.awt.*;
import java.awt.event.*;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class button extends JFrame{
public button(){
JButton button=new JButton("查找");
setLayout(new FlowLayout());
add(button);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
selectinterface sl = new selectinterface();
sl.setVisible(true);
sl.pack();
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
button frame=new button();
frame.setTitle("按钮");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,600);
frame.setVisible(true);
}
}
class selectinterface extends JFrame{
public selectinterface(){
JPanel p1=new JPanel();
p1.setLayout(new GridLayout(9,2,5,5));
p1.add(new JLabel("编号"));
p1.add(new JTextField(6));
p1.add(new JLabel("姓名"));
p1.add(new JTextField(8));
p1.add(new JLabel("性别"));
p1.add(new JTextField(1));
p1.add(new JLabel("年龄"));
p1.add(new JTextField(2));
p1.add(new JLabel("职位"));
p1.add(new JTextField(20));
p1.add(new JLabel("学历"));
p1.add(new JTextField(4));
p1.add(new JLabel("学位"));
p1.add(new JTextField(4));
p1.add(new JLabel("工龄"));
p1.add(new JTextField(2));
p1.add(new JLabel("工资等级"));
p1.add(new JTextField(2));
JPanel p2=new JPanel();
p2.add(new JButton("确定"));
p2.add(new JButton("取消"));
setLayout(new GridLayout(2,1,0,100));
add(p1);
add(p2);
}
}
import java.awt.event.*;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class button extends JFrame{
public button(){
JButton button=new JButton("查找");
setLayout(new FlowLayout());
add(button);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
selectinterface sl = new selectinterface();
sl.setVisible(true);
sl.pack();
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
button frame=new button();
frame.setTitle("按钮");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,600);
frame.setVisible(true);
}
}
class selectinterface extends JFrame{
public selectinterface(){
JPanel p1=new JPanel();
p1.setLayout(new GridLayout(9,2,5,5));
p1.add(new JLabel("编号"));
p1.add(new JTextField(6));
p1.add(new JLabel("姓名"));
p1.add(new JTextField(8));
p1.add(new JLabel("性别"));
p1.add(new JTextField(1));
p1.add(new JLabel("年龄"));
p1.add(new JTextField(2));
p1.add(new JLabel("职位"));
p1.add(new JTextField(20));
p1.add(new JLabel("学历"));
p1.add(new JTextField(4));
p1.add(new JLabel("学位"));
p1.add(new JTextField(4));
p1.add(new JLabel("工龄"));
p1.add(new JTextField(2));
p1.add(new JLabel("工资等级"));
p1.add(new JTextField(2));
JPanel p2=new JPanel();
p2.add(new JButton("确定"));
p2.add(new JButton("取消"));
setLayout(new GridLayout(2,1,0,100));
add(p1);
add(p2);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询