?? 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 + -