import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import info.clearthought.layout.TableLayout;
public class Map2 extends JFrame, JPanel implements ItemListener{
public static void main(String[] arguments){
Map2 frame = new Map2();
frame.show();
}
JButton but;
JComboBox cobo;
String itemVal;
Container content;
public Map2(){
super("Map2");
setSize(350, 350);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
double Sizes[][] = {{160, 160},
{290, TableLayout.PREFERRED}};
content = getContentPane();
content.setLayout(new TableLayout(Sizes));
cobo = new JComboBox();
cobo.addItemListener(this);
cobo.addItem("Viereck");
cobo.addItem("Kreis");
cobo.addItem("Dreieck");
cobo.addItem("Ellipse");
cobo.setEditable(false);
content.add(cobo, "0, 1, 0 ,0");
but = new JButton("close");
content.add(but, "1, 1, 0, 0");
but.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
}
public void itemStateChanged(ItemEvent e, Graphics comp){
Graphics2D comp2D = (Graphics2D)comp;
Object newPick = e.getItem();
if(newPick.toString() == "Viereck"){
comp2D.setColor(Color.blue);
Rectangle2D.Float map = new Rectangle2D.Float(10F, 10F, 100F, 100F);
comp2D.fill(map);
}
if(newPick.toString() == "Dreieck"){
comp2D.setColor(Color.yellow);
GeneralPath linie = new GeneralPath();
linie.moveTo(110F, 120F);
linie.lineTo(160F, 220F);
linie.lineTo(60F, 220F);
linie.closePath();
comp2D.fill(linie);
}
if(newPick.toString() == "Kreis"){
Kreis mappe = new Kreis();
content.add(mappe, "0, 0, 1, 0");
}
if(newPick.toString() == "Ellipse"){
Ellipse mappe = new Ellipse();
content.add(mappe, "0, 0, 1, 0");
setVisible(true);
setSize(350, 350);
}
}
}
class Form extends JPanel {
public void viereck(Graphics comp){
Graphics2D comp2D = (Graphics2D)comp;
// erzeugt ein Viereck
comp2D.setColor(Color.blue);
Rectangle2D.Float background = new Rectangle2D.Float(10F, 10F, 100F, 100F);
comp2D.fill(background);
}
public void kreis(Graphics comp){
Graphics2D comp2D = (Graphics2D)comp;
// erzeugt einen Kreis
comp2D.setColor(Color.red);
Arc2D.Float circle = new Arc2D.Float(120F, 10F, 100F, 100F, 0F, 360F, Arc2D.OPEN);
comp2D.fill(circle);
}
public void ellipse(Graphics comp){
Graphics2D comp2D = (Graphics2D)comp;
//erzeugt eine Ellipse
comp2D.setColor(Color.green);
Ellipse2D.Float ellipt = new Ellipse2D.Float(240, 10, 75, 100);
comp2D.fill(ellipt);
}
public void dreieck(Graphics comp){
Graphics2D comp2D = (Graphics2D)comp;
//Dreieck durch Linien
comp2D.setColor(Color.yellow);
GeneralPath linie = new GeneralPath();
linie.moveTo(110F, 120F);
linie.lineTo(160F, 220F);
linie.lineTo(60F, 220F);
linie.closePath();
comp2D.fill(linie);
}
}