GRAF von GRAPH
parent
9b0b57aa5c
commit
4b38883cd9
|
@ -0,0 +1,13 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
public class ButtonAAAAAction implements ActionListener
|
||||
{
|
||||
private String text;
|
||||
public ButtonAAAAAction(String t){
|
||||
this.text = t;
|
||||
}
|
||||
public void actionPerformed(ActionEvent e){
|
||||
System.out.println(this.text);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
|
||||
|
||||
public class MyPanel extends JPanel
|
||||
{
|
||||
public boolean linie = false;
|
||||
public boolean kreis = false;
|
||||
int x = 100;
|
||||
int y = 100000000;
|
||||
@Override
|
||||
protected void paintComponent(Graphics g){
|
||||
super.paintComponent(g);
|
||||
|
||||
if (linie) g.drawLine(20,20,200,50);
|
||||
if (kreis) g.drawOval(50, 50, 30, 30);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Window implements ActionListener
|
||||
{
|
||||
private JFrame fenster;
|
||||
private MyPanel panel;
|
||||
private JButton button;
|
||||
private JButton button2;
|
||||
public Window(){
|
||||
fenster = new JFrame("Mein erstes Fenster");
|
||||
fenster.setSize(400,400);
|
||||
|
||||
panel = new MyPanel();
|
||||
|
||||
fenster.add(panel);
|
||||
panel.setBackground(new Color(100,100,100));
|
||||
|
||||
button = new JButton ("Linie");
|
||||
panel.add(button);
|
||||
button.addActionListener(this);
|
||||
|
||||
button2 = new JButton("Kreis");
|
||||
panel.add(button2);
|
||||
button2.addActionListener(this);
|
||||
|
||||
|
||||
fenster.setVisible(true);
|
||||
|
||||
fenster.addMouseListener(new MouseListener(){
|
||||
public void MouseEntered(MouseEvent e){};
|
||||
public void MousePressed(MouseEvent e){
|
||||
System.out.println("( " + e.getPoint().getX() + " | " + e.getPoint().getY() + " )");
|
||||
panel.x = (int)e.getPoint().getX();
|
||||
panel.y = (int)e.getPoint().getY();
|
||||
fenster.repaint();
|
||||
|
||||
};
|
||||
public void MouseReleased(MouseEvent e){};
|
||||
public void MouseCicked(MouseEvent e){};
|
||||
public void MouseExited(MouseEvent e){};
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void actionPerformed(ActionEvent e){
|
||||
if (e.getSource() == this.button) panel.linie = !panel.linie;
|
||||
if (e.getSource() == this.button2) panel.kreis = !panel.kreis;
|
||||
fenster.repaint();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue