package clash_editor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.io.File;
import java.awt.*;
import javax.imageio.ImageIO;
import javax.swing.*;
public class Auswahl extends JFrame{
JLabel map=new JLabel("Map:");
JTextField mappfad=new JTextField("D:\\HAUBOLD_DATEN\\map.gif");
JButton buttonpfad=new JButton("Map");
JLabel xanz=new JLabel("X-Anzahl:");
JLabel yanz=new JLabel("Y-Anzahl:");
JTextField x=new JTextField("20");
JTextField y=new JTextField("15");
JButton ok=new JButton("Start");
public Auswahl(){
super("Clash-Editor");
this.setResizable(false);
this.setSize(304, 125);
this.setVisible(true);
this.setLayout(null);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(null);
setelements();
loadelements();
}
public void setelements(){
setsizelocation(map, 5, 5, 290, 15);
setsizelocation(mappfad, 5, 20, 195, 25);
setsizelocation(buttonpfad, 200, 20, 95, 25);
setsizelocation(xanz, 5, 50, 100, 10);
setsizelocation(yanz, 105, 50, 100, 10);
setsizelocation(x, 5, 65, 100, 25);
setsizelocation(y, 100, 65, 100, 25);
setsizelocation(ok, 200, 50, 95, 40);
buttonpfad.addActionListener(new ActionListener() {//Dem Button wird ein Filechoser angehangen
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == buttonpfad) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.showOpenDialog(Auswahl.this);
File fileSelected = fileChooser.getSelectedFile();
mappfad.setText(fileSelected.getAbsolutePath());
}
}
});
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
new Editor(mappfad.getText(),x.getText(),y.getText());
}
});
}
public void loadelements(){
this.add(map);
this.add(mappfad);
this.add(buttonpfad);
this.add(xanz);
this.add(yanz);
this.add(x);
this.add(y);
this.add(ok);
}
public void setsizelocation(JComponent c,int x,int y,int breite,int hoehe){//schnelles Plazieren von Componenten
c.setSize(breite, hoehe);
c.setLocation(x, y);
}
public static void main(String[] args) {
Auswahl main=new Auswahl();
}
}
class Editor extends JFrame{
JPanel mappanel=new JPanel();
BufferedImage karte;
String pfad;
int xanz,yanz;
JLabel maplabel;
public Editor(String pfad,String xanz,String yanz){
super("Clash-Editor");
try {
karte=ImageIO.read(new File(pfad));
} catch (Exception e) {
}
maplabel=new JLabel(new ImageIcon(karte));
this.pfad=pfad;
this.xanz=Integer.parseInt(xanz);
this.yanz=Integer.parseInt(yanz);
this.setResizable(false);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setSize(800,600);
this.setVisible(true);
this.setLayout(null);
this.setsizelocation(maplabel, 0, 0, karte.getWidth(), karte.getHeight());
mappanel.setSize(karte.getWidth(),karte.getHeight());
mappanel.add(maplabel);
this.add(mappanel);
setelements();
}
public void setelements(){
JButton setgitteran = new JButton("Gitter An");
JButton setgitteraus = new JButton("Gitter Aus");
setsizelocation(setgitteran, 10, 480, 100, 32);
setsizelocation(setgitteraus, 110, 480, 100, 32);
setgitteran.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
rasteran();
}
});
setgitteraus.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
rasteraus();
}
});
this.add(setgitteran);
this.add(setgitteraus);
}
public void rasteran(){
System.out.println("an");
}
public void rasteraus(){
System.out.println("aus");
}
public void setsizelocation(JComponent c,int x,int y,int breite,int hoehe){//schnelles Plazieren von Componenten
c.setSize(breite, hoehe);
c.setLocation(x, y);
}
}