99 lines
3.0 KiB
Java
99 lines
3.0 KiB
Java
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;
|
|
private JButton button3;
|
|
private JButton button4;
|
|
|
|
public Window(){
|
|
fenster = new JFrame("Mein erstes Fenster");
|
|
fenster.setSize(400,400);
|
|
|
|
fenster.setLayout( new BorderLayout());
|
|
|
|
JPanel top = new JPanel();
|
|
top.setBackground(new Color(170,170,170));
|
|
fenster.add(top, BorderLayout.PAGE_START);
|
|
panel = new MyPanel();
|
|
|
|
fenster.add(panel, BorderLayout.CENTER);
|
|
panel.setBackground(new Color(100,100,100));
|
|
|
|
button = new JButton ("Speichern");
|
|
top.add(button);
|
|
button.addActionListener(this);
|
|
|
|
button2 = new JButton("Laden");
|
|
top.add(button2);
|
|
button2.addActionListener(this);
|
|
|
|
button3 = new JButton("Clear");
|
|
top.add(button3);
|
|
button3.addActionListener(this);
|
|
|
|
button4 = new JButton("Tiefensuche");
|
|
top.add(button4);
|
|
button4.addActionListener(this);
|
|
|
|
|
|
fenster.setVisible(true);
|
|
panel.addMouseMotionListener(new MouseMotionListener(){
|
|
public void mouseDragged(MouseEvent e){
|
|
panel.move((int) e.getPoint().getX(), (int) e.getPoint().getY());
|
|
fenster.repaint();}
|
|
|
|
public void mouseMoved(MouseEvent e){
|
|
panel.move((int) e.getPoint().getX(), (int) e.getPoint().getY());
|
|
fenster.repaint();
|
|
}
|
|
});
|
|
panel.addMouseListener(new MouseListener(){
|
|
public void mouseEntered(MouseEvent e){};
|
|
|
|
public void mousePressed(MouseEvent e){
|
|
if (e.getButton()== MouseEvent.BUTTON1){
|
|
panel.press((int) e.getPoint().getX(), (int) e.getPoint().getY());
|
|
}
|
|
if (e.getButton()== MouseEvent.BUTTON3){
|
|
panel.right((int) e.getPoint().getX(), (int) e.getPoint().getY());
|
|
}
|
|
fenster.repaint();
|
|
|
|
};
|
|
|
|
public void mouseReleased(MouseEvent e){
|
|
panel.released((int) e.getPoint().getX(), (int) e.getPoint().getY());
|
|
fenster.repaint();
|
|
};
|
|
|
|
public void mouseClicked(MouseEvent e){};
|
|
|
|
public void mouseExited(MouseEvent e){};
|
|
|
|
});
|
|
}
|
|
|
|
public void actionPerformed(ActionEvent e){
|
|
if (e.getSource() == this.button) {
|
|
panel.save();
|
|
}
|
|
if (e.getSource() == this.button2) {
|
|
panel.load();
|
|
}
|
|
if(e.getSource() == this.button3){
|
|
panel.clear();
|
|
}
|
|
if(e.getSource() == this.button4){
|
|
panel.tiefensuche();
|
|
}
|
|
fenster.repaint();
|
|
}
|
|
}
|
|
|