📄 luiyanb.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.lang.String;
public class LuiYanB{
Frame fc=new Frame("留言簿窗口");
private Label lb[]=new Label[5];
private TextField tf[]=new TextField[3];
private TextArea ta=new TextArea(5,30);
private Button btn[]=new Button[2];
private Panel pl;
public Font f=new Font("宋体",Font.BOLD,14);
public String nameStr,emailStr,titleStr,contentStr;
LuiYanB(){
pl=new Panel(new GridLayout(6,1));
lb[1]=new Label("姓名:");
pl.add(lb[1]);
tf[0]=new TextField(12);
pl.add(tf[0]);
lb[2]=new Label("Email:");
pl.add(lb[2]);
tf[1]=new TextField(20);
pl.add(tf[1]);
lb[3]=new Label("主题");
pl.add(lb[3]);
tf[2]=new TextField(20);
pl.add(tf[2]);
lb[4]=new Label("留言");
pl.add(lb[4]);
pl.add(ta);
btn[0]=new Button("提交留言");
pl.add(btn[0]);
btn[1]=new Button("清除");
pl.add(btn[1]);
fc.add(pl);
fc.setFont(f);
fc.setSize(300,150);
fc.setBackground(Color.cyan);
fc.setForeground(Color.blue);
fc.setResizable(false);
fc.setLocation(200,150);
fc.setVisible(true);
//把文本框中的内容取出赋给变量
btn[0].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getSource()==btn[0]){
nameStr=tf[0].getText();
emailStr=tf[1].getText();
titleStr=tf[2].getText();
contentStr=ta.getText();
DisplayLuiYan dly=new DisplayLuiYan(nameStr,emailStr,titleStr,contentStr);
//Dispose();
}
}
});
//清空文本框中的内容
btn[1].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf[0].setText("");
tf[1].setText("");
tf[2].setText("");
ta.setText("");
}
});
//关闭窗口
fc.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e){
e.getWindow().dispose();
//System.exit(0);
}
});
}
//public static void main(String[] args){
// new LuiYanB();
//}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -