* Created by Administrator on 2015/6/20.
*/
class PersonA {
private String name
public void setName(String newName) {
name = newName
}
public String getName() {
return name
}
} //缺了 花括号
class StudentA extends PersonA //_____________________//【代码1】继承personA类
{
private String department
public void setDepartment(String newDepartment) {
department = newDepartment
}
public String getDepartment() {
return department
}
}
public class C1 {
public static void main(String[] args) {
StudentA s1 = new StudentA()
// ____________________________//【代码2】调用setName方法传入参数“张三”
s1.setName("张三")
//________________________________//【代码3】调用setDepartment
s1.setDepartment("信管系")
//方法传入参数“信管系”
//________________________________//【代码4】显示s1的姓名
System.out.println(s1.getName())
//________________________________//【代码5】显示s1的系别
System.out.println(s1.getDepartment())
}
}
public class CheckBoxWindow extends JFrame implements ItemListener {JCheckBox box// 多选按钮
JLabel imageLabel
CheckBoxWindow() {
box = new JCheckBox("显示图像")
imageLabel = new JLabel(new ImageIcon("1.jpg"))
imageLabel.setVisible(false)
add(box, BorderLayout.NORTH)
add(imageLabel, BorderLayout.CENTER)
validate()
box.addItemListener(this)// 为box增加监听器
setBounds(120, 120, 260, 270)
setVisible(true)
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
}
public void itemStateChanged(ItemEvent e) {
JCheckBox box = (JCheckBox) e.getItemSelectable()
if (box.isSelected()) // 如果多选按钮被选中
imageLabel.setVisible(true)
else imageLabel.setVisible(false)
}
}
1 ItemListener
2 this
3 box.isSelected()
public void add(int a,int b){System.out.println(a+"+"+b+"="+(a+b))
}
public void show(){
System.out.println("show方法执行了!")
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)