public class StatisticFrame extends JFrame{
public StatisticFrame(){
init();
}
private JTable table;
private void init() {
this.setTitle("statistic");
this.setSize(600, 300);
JToolBar toolBar = new JToolBar();
JButton button1 = new JButton("应用层");
JButton button2 = new JButton("网络层");
JButton button3 = new JButton("数据链路层");
toolBar.add(button1);
toolBar.add(button2);
toolBar.add(button3);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Vector head = new Vector();
head.add("端口");
head.add("协议");
head.add("位置");
DefaultTableModel model = new DefaultTableModel(null,head);
table= new JTable(model);
JScrollPane pane = new JScrollPane(table);
add(pane);
}
});
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Vector head = new Vector();
head.add("协议");
head.add("位置");
DefaultTableModel model = new DefaultTableModel(null,head);
table= new JTable(model);
JScrollPane pane = new JScrollPane(table);
add(pane);
}
});
this.add(BorderLayout.NORTH,toolBar);
} public static void main(String[] args) {
StatisticFrame frame = new StatisticFrame();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
当我点击JButton1时如何生成一个Jtable在主窗口区,求教!Jbutton,Jtable
public StatisticFrame(){
init();
}
private JTable table;
private void init() {
this.setTitle("statistic");
this.setSize(600, 300);
JToolBar toolBar = new JToolBar();
JButton button1 = new JButton("应用层");
JButton button2 = new JButton("网络层");
JButton button3 = new JButton("数据链路层");
toolBar.add(button1);
toolBar.add(button2);
toolBar.add(button3);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Vector head = new Vector();
head.add("端口");
head.add("协议");
head.add("位置");
DefaultTableModel model = new DefaultTableModel(null,head);
table= new JTable(model);
JScrollPane pane = new JScrollPane(table);
add(pane);
}
});
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Vector head = new Vector();
head.add("协议");
head.add("位置");
DefaultTableModel model = new DefaultTableModel(null,head);
table= new JTable(model);
JScrollPane pane = new JScrollPane(table);
add(pane);
}
});
this.add(BorderLayout.NORTH,toolBar);
} public static void main(String[] args) {
StatisticFrame frame = new StatisticFrame();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
当我点击JButton1时如何生成一个Jtable在主窗口区,求教!Jbutton,Jtable
解决方案 »
- 小菜鸟请问各位牛人关于JFileChooser
- 新人求助 jdbc Access 连接不上
- 如何获取网页被哪些蜘蛛爬过?
- 怎么样从数据库里面的表的内容生成一张列表显示在jsp页面里
- Runtime的问题
- eclipse中有关PROJECT的问题
- 关于socket:如何判断连接超时?
- 消息中间件的功能?各位铜人帮忙!
- 什么问题:Exception in thread "main" java.lang.NoClassDefFoundError:test(runtime)
- 各位问一下!!什末是中间件,作用是什末???谢谢!
- 有两个疑惑,请各位大叔大婶指点一下:TreeSet是怎么排序的?接口中的方法为什么可以不用全部实现?
- 请问如何解决spring+jdbc的死锁问题
import javax.swing.*;
import javax.swing.table.DefaultTableModel;public class StatisticFrame extends JFrame implements ActionListener {
public StatisticFrame() {
init();
} private JTable table;
Vector head = new Vector();
JButton button1; private void init() {
this.setTitle("statistic");
this.setSize(600, 300);
DefaultTableModel model = new DefaultTableModel(null, head);
table = new JTable(model);
JScrollPane pane = new JScrollPane(table);
JToolBar toolBar = new JToolBar();
button1 = new JButton("应用层");
JButton button2 = new JButton("网络层");
JButton button3 = new JButton("数据链路层");
toolBar.add(button1);
toolBar.add(button2);
toolBar.add(button3);
this.add(pane);
button1.addActionListener(this);
this.add(BorderLayout.NORTH, toolBar);
} public static void main(String[] args) {
StatisticFrame frame = new StatisticFrame();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} @Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == button1) {
head.add("端口");
head.add("协议");
head.add("位置");
DefaultTableModel model = new DefaultTableModel(null, head);
table.setModel(model);
}
}
}