Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class Starthere extends JFrame {
- private static final long serialVersionUID = 1L;
- private JButton button1;
- private JButton button2;
- public Figur figur1;
- public Figur figur2;
- Starthere() {
- setSize(900, 900);
- setResizable(false);
- setVisible(true);
- JPanel panel1 = new JPanel();
- JPanel panel2 = new JPanel();
- figur1 = new Kreis(Color.BLACK, 10, 10, 100);
- figur2 = new Kreis(Color.WHITE, 100, 100, 100);
- //figur2 = new Rechteck(Color.BLUE, 0, 0, 100, 100);
- button1 = new JButton("Button 1");
- button1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- figur1.setColor(Color.BLACK);
- figur2.setColor(Color.WHITE);
- figur1.setPos(500, 100);
- repaint();
- }
- });
- button2 = new JButton("Button 2");
- button2.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- figur1.setColor(Color.WHITE);
- figur2.setColor(Color.BLACK);
- repaint();
- }
- });
- panel1.add(button1);
- panel2.add(button2);
- add(panel1, BorderLayout.NORTH);
- add(panel2, BorderLayout.SOUTH);
- }
- @Override
- public void paint(Graphics g) {
- figur1.Draw(g);
- figur2.Draw(g);
- }
- public static void main(String[] args) {
- new Starthere();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement