[Mi:eclipse/workspace/rep#6] j03040% java List Reggae.java
File name:Reggae.java
1:/*
2: * @day: 2004/01/04
3: * @author j03040
4: * @ST-ID 035740F
5: */
6:import java.io.*;
7:import java.awt.*;
8:import java.awt.event.*;
9:public class Reggae extends Frame implements ActionListener,
10:ItemListener{ //ActionListerとItemListenerを実装
11: Button b0=new Button("Show!"); //GUI部品の生成
12: Label x0=new Label("the Graet Reggae Singers!");
13: Label x1=new Label("Genre");
14: Label x2=new Label("Singer");
15: TextField t0=new TextField("Singer Name");
16: Checkbox[] c0=new Checkbox[] {new Checkbox("roots",true),new Checkbox("Dub",true)};
17: List l1 = new List();
18: TextArea t1 = new TextArea();
19: Choice c1 = new Choice();
20: public Reggae(){
21: setLayout(null);
22: add(b0);b0.setBounds(300, 350, 60,30);
23: b0.addActionListener(this);
24: add(x0);x0.setBounds(50,40,70,40);
25: add(x1);x1.setBounds(40,300,100,20);
26: add(x2);x2.setBounds(100,300,100,20);
27: add(t0);t0.setBounds(250,300,100,10);
28: for(int i=0; i<2; i++) {
29: add(c0[i]); c0[i].setBounds(40, 330 + i*25, 60, 20);
30: }//Choiceの中身を追加
31: c1.add("Bob Marley");c1.add("BlackUhuru");
32: c1.add("Peter Tosh");c1.add("Burning Spear");
33: c1.add("King Tubby");c1.add("Lee Pelly");
34: c1.addItemListener(this);
35: add(t1); t1.setBounds(30,80, 300, 200);
36: add(c1);c1.setBounds(100,330,60,30);
37: //add(l1);l1.setBounds(200,112,355,55);
38: t1.append(" Singer profile\n \n");
39: t1.append(" choose singer name \n");
40: t1.append(" and push show Button!\n");
41: }
42: public static void main(String[] args) {
43: Frame aaa= new Reggae() ;
44: aaa.setSize(400,400);
45: aaa.setVisible(true);
46: aaa.setResizable(true);
47: aaa.setTitle(" The Great Reggae Singers!");
48: aaa.addWindowListener(new WindowAdapter() {
49: public void windowClosing(WindowEvent evt) {
50: System.exit(0);
51: }
52: });
53: }
54: public void actionPerformed(ActionEvent e) {
55: String[] txt={"bob.txt","uhuru.txt","tosh.txt","spe.txt","king.txt","lee.txt"};
56: if (c1.getSelectedIndex()==0)Input(txt[0]);
57: else if(c1.getSelectedIndex()==1)Input(txt[1]);
58: else if(c1.getSelectedIndex()==2)Input(txt[2]);
59: else if(c1.getSelectedIndex()==3)Input(txt[3]);
60: else if(c1.getSelectedIndex()==4)Input(txt[4]);
61: else if(c1.getSelectedIndex()==5)Input(txt[5]);
62: else t1.setText("Please choose Singer!");
63: }
64: public void itemStateChanged(ItemEvent e) {
65: String name;
66: int a=c1.getSelectedIndex();
67: t0.setText(c1.getItem(a));
68: }
69: public void Input(String argv){ //ファイルの中身を読み込む
70: t1.setText(" ");
71: try {
72: String s;
73: int a=0;
74: FileReader fr = new FileReader(argv);
75: BufferedReader in = new BufferedReader(fr);
76: while ((s=in.readLine())!=null) {
77: t1.append(s+"\n");
78: a++;
79: }
80:
81: in.close();
82: }catch(Exception e){
83: t1.setText("Error!! \n"+e.toString());
84: }
85: }
86:}
87:
|