随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)
package com;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
public class TableJFrame extends JFrame {
public TableJFrame() {
this.setLayout(null);
// 选项卡对象
JTabbedPane jtp = new JTabbedPane();
jtp.setBounds(50, 50, 300, 200);
this.add(jtp);
// JPanel jp1=new JPanel();
// jp1.setLayout(null);
// JButton j1=new JButton("添加");
// j1.setBounds(30, 80, 80, 20);
// jp1.add(j1);
// jtp.add("添加员工",jp1);
jtp.add("添加员工", new OnePanel());
// JPanel jp2=new JPanel();
// jp2.setLayout(null);
// JButton j2=new JButton("删除");
// j2.setBounds(40, 80, 60, 20);
// jp2.add(j2);
// jtp.add("删除员工",jp2);
jtp.add("删除员工", new TwoPanel());
this.setSize(500, 400);
this.setVisible(true);
this.setDefaultCloseOperation(3);
this.setLocationRelativeTo(null);
this.setResizable(false);
}
public static void main(String[] args) {
TableJFrame t = new TableJFrame();
}
}
class OnePanel extends JPanel {
public OnePanel() {
this.setLayout(null);
JButton j = new JButton("添加");
j.setBounds(50, 50, 80, 20);
this.add(j);
}
}
class TwoPanel extends JPanel {
public TwoPanel() {
this.setLayout(null);
JButton j = new JButton("删除");
j.setBounds(50, 50, 80, 20);
this.add(j);
}
}