[자바 예제]
자바 연습 두번째 빙고판을 만들어 봅시다.
역시나 게임을 만들면서 결과를 보며
배우는게
가장 좋은 방법이고
자바를 접하는데 가장 좋습니다. ^^
천천히 따라 결과까지 보시기 바래요~
import java.awt.*; import java.awt.event.*;
class MyGame1 extends Frame { Button apple , q,w,e,r,t,y,u,i,o,p,a,s,d,b,g,h,j,k,l,z,x,c,v,n; MyGame1(String title){ super(title); apple = new Button("사과"); q = new Button("나무");w = new Button("축구");e = new Button("농구");r = new Button("야구"); i = new Button("배");u = new Button("나니");y = new Button("발렌시아");t = new Button("루니"); o = new Button("참외");p = new Button("긱스");a = new Button("드록바");s = new Button("박지성"); j = new Button("에브라");k = new Button("메시");l = new Button("치차리토");z = new Button("베르마토프"); h = new Button("게임");g = new Button("호날두"); b = new Button("퍼디난드"); d = new Button("토레스");x = new Button("제코");c = new Button("이청용"); n = new Button("램파드");v = new Button("제라드"); apple.addActionListener(new EventHandler()); q.addActionListener(new EventHandler()); w.addActionListener(new EventHandler()); e.addActionListener(new EventHandler()); r.addActionListener(new EventHandler()); t.addActionListener(new EventHandler()); y.addActionListener(new EventHandler()); u.addActionListener(new EventHandler()); i.addActionListener(new EventHandler()); o.addActionListener(new EventHandler()); p.addActionListener(new EventHandler()); a.addActionListener(new EventHandler()); s.addActionListener(new EventHandler()); d.addActionListener(new EventHandler()); g.addActionListener(new EventHandler()); b.addActionListener(new EventHandler()); h.addActionListener(new EventHandler()); j.addActionListener(new EventHandler()); k.addActionListener(new EventHandler()); l.addActionListener(new EventHandler()); z.addActionListener(new EventHandler()); x.addActionListener(new EventHandler()); c.addActionListener(new EventHandler()); v.addActionListener(new EventHandler()); n.addActionListener(new EventHandler());
setLayout(new GridLayout(5,5)); setSize(300,300); setVisible(true); add(q);add(w);add(e);add(r);add(t);add(y);add(u);add(i);add(o);add(p);add(a);add(s);add(d);add(b);add(g);add(h);add(j); add(k);add(l);add(z);add(apple);add(x);add(c);add(v);add(n);
} class EventHandler implements ActionListener{ public void actionPerformed(ActionEvent e){ Button cb= (Button)e.getSource(); String cc = cb.getLabel(); System.out.println(cc); cb.setBackground(Color.red); } }
public static void main(String[] args) { new MyGame1("MyGame");
} } |