📄 hw17_15.java
字号:
import java.awt.*;
import java.awt.event.*;
public class hw17_15 extends Frame implements ActionListener
{
static hw17_15 frm=new hw17_15();
static Dialog dlg=new Dialog(frm);
static Button change_btn=new Button("Change Color");
static Button ok_btn=new Button("Ok");
static Button Cancel_btn=new Button("Cancel");
static Checkbox ckb1=new Checkbox("Green");
static Checkbox ckb2=new Checkbox("Yellow");
static Checkbox ckb3=new Checkbox("White");
static WinLis wlis=new WinLis();
public static void main(String args[])
{
CheckboxGroup grp=new CheckboxGroup();
frm.setTitle("Frame");
frm.setSize(200,150);
dlg.setTitle("Dialog");
dlg.setSize(150,100);
frm.setLayout(null);
dlg.setLayout(null);
ckb1.setCheckboxGroup(grp);
ckb2.setCheckboxGroup(grp);
ckb3.setCheckboxGroup(grp);
change_btn.setBounds(40,40,120,30);
ckb1.setBounds(10,20,60,30);
ckb2.setBounds(10,40,60,30);
ckb3.setBounds(10,60,60,30);
ok_btn.setBounds(80,40,50,20);
Cancel_btn.setBounds(80,60,50,20);
dlg.add(ckb1);
dlg.add(ckb2);
dlg.add(ckb3);
dlg.add(ok_btn);
dlg.add(Cancel_btn);
frm.add(change_btn);
Cancel_btn.addActionListener(frm);
change_btn.addActionListener(wlis);
ok_btn.addActionListener(frm);
frm.setVisible(true);
}
static class WinLis implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
dlg.setLocation(80,30);
dlg.show();
}
}
public void actionPerformed(ActionEvent c)
{
if(ckb1.getState()==true)
{
Button btn=(Button) c.getSource();
if(btn==ok_btn)
{
dlg.dispose();
frm.setBackground(Color.green);
}
else if (btn==Cancel_btn)
dlg.hide();
}
else if(ckb2.getState()==true)
{
Button btn=(Button) c.getSource();
if(btn==ok_btn)
{
dlg.dispose();
frm.setBackground(Color.yellow);
}
else if (btn==Cancel_btn)
dlg.hide();
}
else if(ckb3.getState()==true)
{
Button btn=(Button) c.getSource();
if(btn==ok_btn)
{
dlg.dispose();
frm.setBackground(Color.white);
}
else if (btn==Cancel_btn)
dlg.hide();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -