Advertisement
Guest User

fgfdg

a guest
Dec 9th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7. import javax.swing.JButton;
  8. import javax.swing.JFrame;
  9. import javax.swing.JPanel;
  10.  
  11. public class Starthere extends JFrame {
  12.  
  13.     private static final long serialVersionUID = 1L;
  14.  
  15.     private JButton button1;
  16.     private JButton button2;
  17.  
  18.     public Figur figur1;
  19.     public Figur figur2;
  20.  
  21.     Starthere() {
  22.         setSize(900, 900);
  23.         setResizable(false);
  24.         setVisible(true);
  25.  
  26.         JPanel panel1 = new JPanel();
  27.         JPanel panel2 = new JPanel();
  28.  
  29.         figur1 = new Kreis(Color.BLACK, 10, 10, 100);
  30.         figur2 = new Kreis(Color.WHITE, 100, 100, 100);
  31.         //figur2 = new Rechteck(Color.BLUE, 0, 0, 100, 100);
  32.  
  33.         button1 = new JButton("Button 1");
  34.         button1.addActionListener(new ActionListener() {
  35.             @Override
  36.             public void actionPerformed(ActionEvent e) {
  37.                 figur1.setColor(Color.BLACK);
  38.                 figur2.setColor(Color.WHITE);
  39.                 figur1.setPos(500, 100);
  40.                
  41.                 repaint();
  42.             }
  43.         });
  44.  
  45.         button2 = new JButton("Button 2");
  46.         button2.addActionListener(new ActionListener() {
  47.             @Override
  48.             public void actionPerformed(ActionEvent e) {
  49.                 figur1.setColor(Color.WHITE);
  50.                 figur2.setColor(Color.BLACK);
  51.                
  52.                 repaint();
  53.             }
  54.         });
  55.  
  56.         panel1.add(button1);
  57.         panel2.add(button2);
  58.  
  59.         add(panel1, BorderLayout.NORTH);
  60.         add(panel2, BorderLayout.SOUTH);
  61.     }
  62.    
  63.     @Override
  64.     public void paint(Graphics g) {
  65.         figur1.Draw(g);
  66.         figur2.Draw(g);
  67.     }
  68.  
  69.     public static void main(String[] args) {
  70.         new Starthere();
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement