1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
public class Interface extends JFrame{
private JLabel label;
private String adressmap = System.getProperty("user.dir")
+ File.separator + "src" + File.separator + "app" + File.separator
+ "graphical_layer" + File.separator + "usa_map.gif";
public Interface(){
super();
build();//Window initialization
}
private void build(){
JMenuBar menuBar = new JMenuBar();
JMenu menu1 = new JMenu("File");
JMenuItem connection = new JMenuItem(new ConnectionAction("Connection"));
menu1.add(connection);
JMenuItem quitter = new JMenuItem(new QuitterAction("Quitter"));
menu1.add(quitter);
menuBar.add(menu1);
JMenu menu2 = new JMenu("Options");
menuBar.add(menu2);
JMenu menu3 = new JMenu("?");
JMenuItem version = new JMenuItem(new VersionAction(this, "Version"));
menu3.add(version);
JMenuItem aPropos = new JMenuItem(new AProposAction(this, "A propos"));
menu3.add(aPropos);
menuBar.add(menu3);
setJMenuBar(menuBar);
setTitle("CriSafe v1.0");
setSize(1024,768);
setLocationRelativeTo(null);
//setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(buildContentPane());
}
private JPanel buildContentPane(){
JPanel panel = new JPanel();
panel.setLayout (new GridBagLayout ());
add (panel);
GridBagConstraints c = new GridBagConstraints();
JButton test1 = new JButton("coucou1");
c.gridx = 0;
c.gridy = 0;
c.gridheight = 1;
c.gridwidth = 2;
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(test1, c);
ImagePanel map = new ImagePanel(new ImageIcon(adressmap).getImage());
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 1;
c.gridheight = 2;
c.weightx = 1.0f;
c.weighty = 1.0f;
c.fill = GridBagConstraints.BOTH;
panel.add(map, c);
Buttons buttons = new Buttons();
c.gridx = 1;
c.gridy = 1;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 0f;
c.weighty = 1.0f;
c.fill = GridBagConstraints.VERTICAL;
panel.add(buttons, c);
Legende leg = new Legende();
c.gridx = 0;
c.gridy = 3;
c.gridwidth = 1;
c.gridheight = 1;
c.weightx = 1.0f;
c.weighty = 0f;
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(leg, c);
JTextArea test4 = new JTextArea("salut");
test4.setEditable(false);
//test4.setEnabled(false);
c.gridx = 1;
c.gridy = 2;
c.ipady = 218;
c.gridwidth = 1;
c.gridheight = 2;
c.weightx = 0f;
c.weighty = 0.0f;
c.fill = GridBagConstraints.BOTH;
panel.add(test4, c);
return panel;
}
class ImagePanel extends JPanel {
private Image img;
public ImagePanel(String img) {
this(new ImageIcon(img).getImage());
}
public ImagePanel(Image img) {
this.img = img;
//Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
//setPreferredSize(size);
//setMinimumSize(size);
//setMaximumSize(size);
//setSize(size);
setLayout(null);
}
public void paintComponent(Graphics g) {
g.drawImage(img, 0, 0, null);
}
}
public JLabel getLabel(){
return label;
}
} |
Partager