So hier ist nochmal meine Hü-Verbesserung mit Gebastel! Viel Spaß beim Testen =) mfg Andy -- GMX DSL: Internet, Telefon und Entertainment für nur 19,99 EUR/mtl.! http://portal.gmx.net/de/go/dsl02
package test; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Uebung extends JFrame implements ActionListener{ private JPanel p4, p5; private JButton b1; private JButton b2; private JButton b3, b4,b5,b6,b7,b8; private JTextField t1; private JLabel radius; private int Zahl; private JLabel text1; public Uebung() { setTitle("Rechner"); setLayout(new FlowLayout()); setSize(400, 460); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); setResizable(false); final Toolkit toolkit = getToolkit(); Dimension size = toolkit.getScreenSize(); setLocation(size.width / 2 - getWidth() / 2, size.height / 2 - getHeight() / 2); JPanel p1 = new JPanel(); p1.setBorder(BorderFactory.createLineBorder(Color.RED, 3)); p1.setPreferredSize(new Dimension(375, 420)); JPanel p2 = new JPanel(); p2.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2)); p2.setPreferredSize(new Dimension(360, 40)); radius = new JLabel("Radius"); t1 = new JTextField(5); t1.addActionListener(this); b3 = new JButton("Reset"); b3.addActionListener(this); p2.add(radius); p2.add(t1); p2.add(b3); JPanel p3 = new JPanel(); p3.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2)); p3.setPreferredSize(new Dimension(360, 40)); b1 = new JButton("Zeichne Kreis"); b1.addActionListener(this); p3.add(b1); b2 = new JButton("Löschen"); b2.addActionListener(this); p3.add(b2); p4 = new JPanel(); p4.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2)); p4.setPreferredSize(new Dimension(360, 270)); p5 = new JPanel(); p5.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2)); p5.setPreferredSize(new Dimension(360, 40)); b4 = new JButton("GrÌn"); b4.addActionListener(this); p5.add(b4); b5 = new JButton("Blau"); b5.addActionListener(this); p5.add(b5); b6 = new JButton("Rot"); b6.addActionListener(this); p5.add(b6); b7 = new JButton("Gelb"); b7.addActionListener(this); p5.add(b7); b8 = new JButton("Orange"); b8.addActionListener(this); p5.add(b8); add(p1); p1.add(p2); p1.add(p3); p1.add(p4); p1.add(p5); } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("Zeichne Kreis")) { Zahl = Integer.parseInt(t1.getText()); Graphics pipi = p4.getGraphics(); pipi.setColor(Color.WHITE); pipi.fillRect(1, 1, 358, 268); pipi.setColor(Color.BLACK); pipi.drawOval(165, 120, Zahl*2, Zahl*2); } if (e.getActionCommand().equals("Löschen")) { Graphics aa = p4.getGraphics(); aa.setColor(Color.WHITE); aa.fillRect(1, 1, 358, 268); } if (e.getActionCommand().equals("Reset")) { t1.setText(""); } if (e.getActionCommand().equals("GrÌn")) { Zahl = Integer.parseInt(t1.getText()); Graphics pipi = p4.getGraphics(); pipi.setColor(Color.GREEN); pipi.fillOval(165, 120, Zahl*2, Zahl*2); } if (e.getActionCommand().equals("Blau")) { Zahl = Integer.parseInt(t1.getText()); Graphics pipi = p4.getGraphics(); pipi.setColor(Color.BLUE); pipi.fillOval(165, 120, Zahl*2, Zahl*2); } if (e.getActionCommand().equals("Rot")) { Zahl = Integer.parseInt(t1.getText()); Graphics pipi = p4.getGraphics(); pipi.setColor(Color.RED); pipi.fillOval(165, 120, Zahl*2, Zahl*2); } if (e.getActionCommand().equals("Gelb")) { Zahl = Integer.parseInt(t1.getText()); Graphics pipi = p4.getGraphics(); pipi.setColor(Color.YELLOW); pipi.fillOval(165, 120, Zahl*2, Zahl*2); } if (e.getActionCommand().equals("Orange")) { Zahl = Integer.parseInt(t1.getText()); Graphics pipi = p4.getGraphics(); pipi.setColor(Color.ORANGE); pipi.fillOval(165, 120, Zahl*2, Zahl*2); } } public static void main(String[] args) { Uebung jens = new Uebung(); } }