📄 data.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
public class Data
{ public static void main(String args[])
{ WindowExit win=new WindowExit();
}
}
class WindowExit extends Frame
{
Mypanel1 yy;
WindowExit()
{
yy=new Mypanel1();
add(yy);
setBounds(100,100,650,500);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ System.exit(0);
}
}
);
validate();
}
}
class Mypanel1 extends Panel implements ActionListener,ItemListener
{ JLabel qq;
Label aa,bb,cc,dd,ee,ff;
Choice a1,b1,c1;
Checkbox box1,box2,box4,box3,box6,box5,box7,box8,box9,box10,box11;
Button ok;
JTextArea show;
CheckboxGroup sex;
CheckboxGroup style;
Box bo1,bo2,bo3,bo5,bo6,bo7,bo4,bo8,bo9,bo10,bo11;
String str1,str2,str3,str4,str5,str6,str7;
Mypanel1()
{
show=new JTextArea();
show.setLineWrap(true);
show.setBackground(Color.yellow);
show.append("班级:");
show.append("软件061班");
show.append("\n");
show.append("我的学号是19");
show.append("\n");
show.append("性别:");
show.append("男");
show.append("\n");
show.append("兴趣:");
show.append("看书 上网");
Font f=new Font("华文隶体",Font.BOLD,19);
show.setFont(f);
show.setEditable(false);
qq=new JLabel(new ImageIcon("我.jpg"));
ok=new Button("确定");
ok.setBackground(Color.cyan);
aa=new Label("班级:");
bb=new Label("学号");
cc=new Label("性别:");
dd=new Label("兴趣:");
ee=new Label("选择在文本框中你希望看到的颜色并按确定:");
ff=new Label("选择在文本框中你希望看到的字体");
sex=new CheckboxGroup();
style=new CheckboxGroup();
box1=new Checkbox("男",true,sex);
box2=new Checkbox("女",false,sex);
box7=new Checkbox("华文隶体",true,style);
box8=new Checkbox("华文中宋",false,style);
box9=new Checkbox("方正姚体",false,style);
box10=new Checkbox("黑体",false,style);
box11=new Checkbox("华文琥珀",false,style);
box7.addItemListener(this);
box8.addItemListener(this);
box9.addItemListener(this);
box10.addItemListener(this);
box11.addItemListener(this);
box3=new Checkbox("听歌",false);
box4=new Checkbox("上网",false);
box5=new Checkbox("看书",true);
box6=new Checkbox("打篮球",false);
a1=new Choice();
a1.add("软件061班");
a1.add("计算机061班");
a1.add("计算机062班");
a1.add("计算机063班");
b1=new Choice();
for(int i=1;i<=31;i++)
b1.add("我的学号是"+i);
c1=new Choice();
c1.add("red");
c1.add("green");
c1.add("orange");
c1.add("cyan");
c1.add("yellow");
c1.add("pink");
ok.addActionListener(this);
bo1=Box.createHorizontalBox();
bo1.add(aa);bo1.add(a1);
bo2=Box.createHorizontalBox();
bo2.add(bb);bo2.add(b1);
bo3=Box.createHorizontalBox();
bo3.add(cc);bo3.add(box1);bo3.add(box2);
bo4=Box.createVerticalBox();
bo4.add(dd);
bo4.add(Box.createVerticalStrut(20));
bo4.add(box3);
bo4.add(Box.createVerticalStrut(20));
bo4.add(box4);
bo4.add(Box.createVerticalStrut(20));
bo4.add(box5);
bo4.add(Box.createVerticalStrut(20));
bo4.add(box6);
bo6=Box.createVerticalBox();
bo6.add(bo1);
bo6.add(Box.createVerticalStrut(20));
bo6.add(bo2);
bo6.add(Box.createVerticalStrut(20));
bo6.add(bo3);
bo6.add(Box.createVerticalStrut(20));
bo6.add(bo4);
bo6.add(Box.createVerticalStrut(20));
bo6.add(ok);
bo6.add(Box.createVerticalStrut(20));
bo8=Box.createVerticalBox();
bo8.add(ff);bo8.add(box7);bo8.add(box8);bo8.add(box9);bo8.add(box10);bo8.add(box11);bo8.add(show);bo8.add(ee);bo8.add(c1);
bo11=Box.createVerticalBox();
bo7=Box.createHorizontalBox();
bo7.add(bo6);
bo7.add(Box.createHorizontalStrut(20));
bo7.add(bo8);
bo7.add(Box.createHorizontalStrut(20));
bo7.add(bo11);
bo7.add(Box.createHorizontalStrut(20));
bo7.add(qq);
setBackground(Color.red);
setLayout(new FlowLayout());
add(bo7);
setBounds(100,100,500,499);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{ show.setText("");
new JLabel(new ImageIcon("4.jpg"));
String str1,str2,str3,str4,str5;
str1=a1.getSelectedItem();
str2=b1.getSelectedItem();
if(box1.getState())
str3=box1.getLabel();
else
str3=box2.getLabel();
str4="";
if(box3.getState())str4=str4+"听歌";
if(box4.getState())str4=str4+" 上网";
if(box5.getState())str4=str4+" 看书";
if(box6.getState())str4=str4+" 打篮球";
String name=c1.getSelectedItem();
if(name.equals("red"))show.setBackground(Color.red);
else if(name.equals("green"))show.setBackground(Color.green);
else if(name.equals("orange"))show.setBackground(Color.orange);
else if(name.equals("cyan"))show.setBackground(Color.cyan);
else if(name.equals("pink"))show.setBackground(Color.pink);
else if(name.equals("yellow"))show.setBackground(Color.yellow);
show.append("班级:");
show.append(str1);
show.append("\n");
show.append(str2);
show.append("\n");
show.append("性别:");
show.append(str3);
show.append("\n");
show.append("兴趣:");
show.append(str4);
}
public void itemStateChanged(ItemEvent e)
{
Checkbox box=(Checkbox)e.getItemSelectable();
if(box.getState())
{
Font f=new Font(box.getLabel(),Font.BOLD,19);
show.setFont(f);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -