2017 《JAVA》实验7 1501 王奕开

(一)学习总结
1.类图:

2. JButton是AbstractButton类的子类,单击时进行处理,加上监听器。
例: private JButton showBtn = new JButton("显示所有宠物");//创建一个按钮
//显示宠物按钮
this.setLayout(null);
tableLabel.setBounds(315,20,122,25);
this.add(tableLabel);
showBtn.setBounds(315,70, 200, 25);
this.add(showBtn);
private void addListener() {
//添加按钮监听
showBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
showPetItem(); //调用添加方法
}
});
}
public void showPetItem(){
//表格,显示信息。
JFrame frame =new JFrame("宠物信息");
JPanel pan =new JPanel();
table.getTableHeader().setReorderingAllowed(false);//列不能移动
table.getTableHeader().setResizingAllowed(true);//可拉动表格
table.setEnabled(false); //不可更改数据
tablePane.setBounds(50, 50, 600, 200);
tablePane.setViewportView(table);//视口装入表格
pan.add(tablePane);
frame.add(pan);
frame.pack();
frame.setLocation(300,200);this.setAlwaysOnTop(true);
frame.setVisible(true);

		}

addActionListener是添加一个活动的监听器,通过创建一个匿名内部类,如果点击按钮时,则调用里面的方法。
If(arg0.getSource()==but){ //判断是否触发按钮
}
例:
Public void windowsActivated(WindowsEvent arg0){
System.out.println(“windowsActivated?窗口被选中”);
}
Public void windowsClosed(WindowsEvent arg0){
System.out.println(“windowsActivated?窗口被关闭”);
}
实现WindowsListener
(三)代码托管
https://git.oschina.net/wangyikai1996/shiyan7.git

posted on 2017-05-11 15:41  一开Stephen  阅读(120)  评论(0)    收藏  举报