Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import java.awt.Color;
- import javax.swing.JLabel;
- import java.awt.BorderLayout;
- import javax.swing.JRadioButton;
- import javax.swing.SwingConstants;
- import java.awt.Window.Type;
- import javax.swing.GroupLayout;
- import javax.swing.GroupLayout.Alignment;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.LayoutStyle.ComponentPlacement;
- import javax.swing.border.BevelBorder;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JTextField;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- public class Frame2 {
- private JFrame frmGroup;
- private JTextField textField;
- private int framewidth = 1000;
- private int frameheight = 600;
- private int mapwidth = 400;
- private int mapheight = 400;
- private Object currentlySelected;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Frame2 window = new Frame2();
- window.frmGroup.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public Frame2() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frmGroup = new JFrame();
- frmGroup.getContentPane().setBackground(new Color(32, 178, 170));
- frmGroup.getContentPane().setForeground(new Color(32, 178, 170));
- frmGroup.setTitle("GROUP 1");
- frmGroup.setBounds(100, 100, 1082, 801);
- frmGroup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JLabel lblMapTypes = new JLabel("FIXED MAP");
- lblMapTypes.setForeground(new Color(255, 0, 0));
- JRadioButton rdbtnCity = new JRadioButton("City");
- JRadioButton rdbtnForest = new JRadioButton("Forest");
- JRadioButton rdbtnWalls = new JRadioButton("Maze");
- JRadioButton rdbtnConstruct = new JRadioButton("construct");
- JLabel lblEditionOptions = new JLabel("CUSTOMIZE");
- lblEditionOptions.setForeground(new Color(255, 0, 0));
- //<<<<<<<<<<<BUTTONS HERE >>>>>>>>
- JButton btnTree = new JButton(new ImageIcon(Frame2.class.getResource("finaltree.jpg")));
- btnTree.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- currentlySelected = new Tree();
- }
- });
- JButton btnTower = new JButton(new ImageIcon(Frame2.class.getResource("Nobility.png")));
- btnTower.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- currentlySelected = new Tower();
- }
- });
- JButton btnStart = new JButton("START");
- JButton btnWall = new JButton(new ImageIcon(Frame2.class.getResource("Small_Rock_Icon.png")));
- btnWall.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- currentlySelected = new Wall();
- }
- });
- JButton btnBuilding = new JButton(new ImageIcon(Frame2.class.getResource("building_icon.jpg")));
- btnBuilding.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- currentlySelected = new Building();
- }
- });
- JButton btnTarget = new JButton(new ImageIcon(Frame2.class.getResource("13-target.png")));
- btnTarget.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- currentlySelected = new Target();
- }
- });
- JButton btnHorizontalWall = new JButton(new ImageIcon(Frame2.class.getResource("Icon-small.jpg")));
- btnHorizontalWall.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- }
- });
- JPanel panel = new JPanel();
- panel.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- System.out.println("Coordinates: (" + e.getX() + ", " + e.getY() + ")");
- if(currentlySelected != null)
- {
- //setCoordinates for currentlySelected object
- currentlySelected = null;
- }
- else
- {
- //check if there's an object at coordinates
- //delete that object from map
- }
- }
- });
- panel.setBorder(new BevelBorder(BevelBorder.LOWERED, null,null, null, null));
- //panel.setSize(mapwidth, mapheight);
- JLabel lblNOfIntruders = new JLabel("N\u00BA of intruders : ");
- textField = new JTextField();
- textField.setColumns(10);
- JButton btnGuards = new JButton(new ImageIcon(Frame2.class.getResource("soldier-icon-1004184133.png")));
- JLabel lblClickInThe = new JLabel("Click in the map to delete");
- GroupLayout groupLayout = new GroupLayout(frmGroup.getContentPane());
- groupLayout.setHorizontalGroup(
- groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGap(143)
- .addComponent(lblNOfIntruders)
- .addPreferredGap(ComponentPlacement.UNRELATED)
- .addComponent(textField, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
- .addGap(59)
- .addComponent(btnGuards))
- .addGroup(groupLayout.createSequentialGroup()
- .addContainerGap()
- .addComponent(lblClickInThe))
- .addGroup(groupLayout.createSequentialGroup()
- .addContainerGap()
- .addComponent(panel, GroupLayout.PREFERRED_SIZE, 600, GroupLayout.PREFERRED_SIZE)))
- .addPreferredGap(ComponentPlacement.RELATED)
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGap(173)
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
- .addComponent(btnBuilding, GroupLayout.PREFERRED_SIZE, 84, GroupLayout.PREFERRED_SIZE)
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
- .addComponent(btnStart, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addComponent(btnWall, 0, 0, Short.MAX_VALUE)
- .addComponent(lblEditionOptions, Alignment.TRAILING)))
- .addGap(30)))
- .addPreferredGap(ComponentPlacement.UNRELATED)
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
- .addComponent(btnTarget, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(btnTower, Alignment.LEADING, 0, 0, Short.MAX_VALUE)
- .addComponent(rdbtnForest, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
- .addComponent(lblMapTypes, GroupLayout.PREFERRED_SIZE, 96, GroupLayout.PREFERRED_SIZE))
- .addContainerGap(113, Short.MAX_VALUE))
- .addGroup(groupLayout.createSequentialGroup()
- .addGap(80)
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addComponent(btnHorizontalWall)
- .addContainerGap())
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addComponent(btnTree, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
- .addComponent(rdbtnCity))
- .addGap(35)
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addComponent(rdbtnConstruct)
- .addContainerGap())
- .addGroup(groupLayout.createSequentialGroup()
- .addComponent(rdbtnWalls, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGap(373))))))))
- );
- groupLayout.setVerticalGroup(
- groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGap(31)
- .addComponent(lblMapTypes)
- .addGap(18)
- .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
- .addComponent(rdbtnWalls)
- .addComponent(rdbtnForest))
- .addGap(26)
- .addComponent(rdbtnConstruct)
- .addGap(18)
- .addComponent(lblEditionOptions)
- .addPreferredGap(ComponentPlacement.RELATED)
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
- .addComponent(btnTower, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
- .addComponent(btnWall, 0, 0, Short.MAX_VALUE))
- .addGap(132)
- .addComponent(btnTree, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE)
- .addGap(7)
- .addGap(41)
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
- .addComponent(btnTarget, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(btnBuilding, 0, 0, Short.MAX_VALUE)
- .addComponent(btnHorizontalWall, GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE))
- .addGap(43)
- .addComponent(btnStart)
- .addGap(85))
- .addGroup(groupLayout.createSequentialGroup()
- .addGap(17)
- .addComponent(lblClickInThe)
- .addGap(18)
- .addComponent(panel, GroupLayout.PREFERRED_SIZE, 600, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(ComponentPlacement.RELATED)))
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGap(16)
- .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
- .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
- .addComponent(lblNOfIntruders)))
- .addGroup(groupLayout.createSequentialGroup()
- .addGap(18)
- .addComponent(btnGuards)))
- .addGap(19))
- .addGroup(groupLayout.createSequentialGroup()
- .addGap(65)
- .addComponent(rdbtnCity)
- .addContainerGap(476, Short.MAX_VALUE))
- );
- frmGroup.getContentPane().setLayout(groupLayout);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement