import java.awt.*;
import javax.swing.*;
public class Test extends JFrame{//把需要的元件全部在這裡定義
JTextArea wby;//文字域
JPanel mb;
JComboBox xlk;//下拉框
JButton an;
JTextField wbk;//文字框
JScrollPane gd;
public static void main(String[] args){
Test lx=new Test();
}
public Test(){
wby=new JTextArea();
mb=new JPanel();
String[] lt={"悟空","八戒","沙僧","小白龍"};
xlk=new JComboBox(lt);
wbk=new JTextField(10);
an=new JButton("傳送");
gd=new JScrollPane(wby);
mb.add(xlk);mb.add(wbk);mb.add(an);
this.add(gd);this.add(mb,BorderLayout.SOUTH);
this.setTitle("聊天視窗");
this.setSize(500,300);
this.setIconImage((new ImageIcon("image/qq.jpg")).getImage());//左上角標籤欄新增小圖示
this.setLocation(300,280);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
![](https://i.iter01.com/images/526b5103382abced882b762635afce80a4dfa643ab03984d0407950418da787b.png)