📄 mywindow.java
字号:
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
//发悄悄话的弹出式窗口类Mywindow
class Mywindow extends Frame implements ActionListener{
TextField text1,text2;
Button button1,button2;
//构造方法初始化画出弹出式窗口界面
Mywindow(){
super("发悄悄话窗口");
setLayout(new GridLayout(3,2));
text1=new TextField(12);
text2=new TextField(8);
button1=new Button("送出悄悄话");
button2=new Button("关闭此窗口");
add(new Label("送悄悄话到:"));
add(text1);
add(new Label("输入您的悄悄话:"));
add(text2);
add(button2);
add(button1);
setSize(400,190);
text1.setEditable(false);
setVisible(false);
button1.addActionListener(this);
button2.addActionListener(this);
setBackground(Color.pink);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{ setVisible(false);System.exit(0);}
}
);
}
//处理按钮事件的方法
public void actionPerformed(ActionEvent e){
if(e.getSource()==button1){
try{chatappletthree.out.writeUTF("悄悄地对"+text1.getText()+"说:"
+text2.getText()+"(我是"+chatappletthree.name+")");
}
catch(IOException e1){}
}
else if(e.getSource()==button2)//关闭窗口
{ this.setVisible(false);}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -