this.setTitle("kare ve daire çizimi"); this.setSize(400,500); this.setLocation(300, 100); |
Button ciz = new Button("çiz"); Button sil = new Button("sil"); Button buyut = new Button("+"); Button kucult = new Button("-"); |
ciz.addActionListener(this); sil.addActionListener(this); buyut.addActionListener(this); kucult.addActionListener(this); |
sekiller = new Choice(); sekiller.add("kare"); sekiller.add("daire"); |
Panel tuslar = new Panel(); |
tuslar.setBackground(Color.GREEN); |
tuslar.add(ciz); tuslar.add(sil); tuslar.add(buyut); tuslar.add(kucult); tuslar.add(sekiller); |
this.add(tuslar,BorderLayout.SOUTH); |
public void paint(Graphics g) { g.setColor(Color.red); if (sekiller.getSelectedItem().equals("kare")) g.fillRect(x1, y1, x2, y2); if (sekiller.getSelectedItem().equals("daire")) g.fillOval(x1, y1, x2, y2); } |
g.setColor(Color.red); Int x1, y1, x2, y2; |
public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("çiz")) { x1 = 50; x2 = 10; y1 = 50; y2 = 10; } if (e.getActionCommand().equals("sil")) { x2 = 0; y2 = 0; } if (e.getActionCommand().equals("+")) { x2 += 5; y2 += 5; } else if (e.getActionCommand().equals("-")) { x2 -= 5; y2 -= 5; } repaint(); } |
this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); |
public static void main(String arg[]){ new Cizim().setVisible(true); } |
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class Cizim extends Frame implements ActionListener { int x1,x2,y1,y2; Choice sekiller; public Cizim() { this.setTitle("kare ve daire çizimi"); this.setSize(400,500); this.setLocation(300, 100); this.setBackground(Color.BLUE); Button ciz = new Button("çiz"); Button sil = new Button("sil"); Button buyut = new Button("+"); Button kucult = new Button("-"); ciz.addActionListener(this); sil.addActionListener(this); buyut.addActionListener(this); kucult.addActionListener(this); sekiller = new Choice(); sekiller.add("kare"); sekiller.add("daire"); Panel tuslar = new Panel(); tuslar.setBackground(Color.GREEN); tuslar.add(ciz); tuslar.add(sil); tuslar.add(buyut); tuslar.add(kucult); tuslar.add(sekiller); this.add(tuslar,BorderLayout.SOUTH); this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); } public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("çiz")){ x1=50; x2=10; y1=50; y2=10; } if(e.getActionCommand().equals("sil")){ x2=0; y2=0; } if(e.getActionCommand().equals("+")){ x2+=5; y2+=5; } else if(e.getActionCommand().equals("-")){ x2-=5; y2-=5; } repaint(); } @Override public void paint(Graphics g){ g.setColor(Color.red); if(sekiller.getSelectedItem().equals("kare")) g.fillRect(x1, y1, x2, y2); if(sekiller.getSelectedItem().equals("daire")) g.fillOval(x1, y1, x2, y2); } public static void main(String arg[]){ new Cizim().setVisible(true); } |