Expand|Select|Wrap|Line Numbers
- public class RiskFrame extends JFrame implements ActionListener, MouseListener{
- private BufferedImage bImage;
- private Image image;
- private JPanel topPanel = new JPanel();
- private JPanel bottomPanel = new JPanel();
- private JPanel centerPanel = new JPanel();
- private JPanel rightPanel = new JPanel();
- private JButton saveButton = new JButton("Save", new ImageIcon("save.jpg"));
- private JButton openButton = new JButton("Open", new ImageIcon("OpenIcon.gif"));
- private static JButton newButton = new JButton("New");
- private JButton addTerritory = new JButton("Add New");
- private JButton removeTerritory = new JButton(" Remove");
- private JLabel goodStatus = new JLabel();
- private JLabel badStatus = new JLabel();
- private JPanel territoryPanel = new JPanel();
- private JLabel territoryInfo = new JLabel("Territory Info");
- private JLabel country = new JLabel("Country: ");
- private JTextField countryField = new JTextField(20);
- private JPanel countryComp = new JPanel();
- private JLabel continent = new JLabel("Continent: ");
- private JTextField continentField = new JTextField(20);
- private JPanel continentComp = new JPanel();
- private JLabel cardType = new JLabel("Card Type: ");
- private JTextField cardField = new JTextField(20);
- private JPanel cardComp = new JPanel();
- private JLabel redColor = new JLabel("R Color #: ");
- private JTextField redColorField = new JTextField(20);
- private JPanel redComp = new JPanel();
- private JLabel greenColor = new JLabel("G Color #: ");
- private JTextField greenColorField = new JTextField(20);
- private JPanel greenComp = new JPanel();
- private JLabel blueColor = new JLabel("B Color #: ");
- private JTextField blueColorField = new JTextField(20);
- private JPanel blueComp = new JPanel();
- public RiskFrame(){
- layoutGUI();
- centerPanel.addMouseListener(this);
- }
- public void layoutGUI(){
- topPanel.add(newButton);
- topPanel.add(openButton);
- topPanel.add(saveButton);
- topPanel.add(addTerritory);
- topPanel.add(removeTerritory);
- bottomPanel.add(goodStatus);
- rightPanel.setLayout(new BorderLayout());
- rightPanel.add(territoryInfo, BorderLayout.NORTH);
- territoryPanel.setLayout(new BoxLayout(territoryPanel, BoxLayout.Y_AXIS));
- territoryPanel.setAlignmentX(LEFT_ALIGNMENT);
- territoryPanel.add(Box.createRigidArea(new Dimension(5,5)));
- countryComp.add(country);
- countryComp.add(countryField);
- continentComp.add(continent);
- continentComp.add(continentField);
- cardComp.add(cardType);
- cardComp.add(cardField);
- redComp.add(redColor);
- redComp.add(redColorField);
- blueComp.add(blueColor);
- blueComp.add(blueColorField);
- greenComp.add(greenColor);
- greenComp.add(greenColorField);
- territoryPanel.add(countryComp);
- territoryPanel.add(continentComp);
- territoryPanel.add(cardComp);
- territoryPanel.add(redComp);
- territoryPanel.add(greenComp);
- territoryPanel.add(blueComp);
- rightPanel.add(territoryPanel, BorderLayout.CENTER);
- this.add(topPanel, BorderLayout.NORTH);
- this.add(rightPanel, BorderLayout.EAST);
- this.add(centerPanel, BorderLayout.CENTER);
- this.add(bottomPanel, BorderLayout.SOUTH);
- newButton.addActionListener(this);
- openButton.addActionListener(this);
- saveButton.addActionListener(this);
- addTerritory.addActionListener(this);
- removeTerritory.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e){
- String command = e.getActionCommand();
- if (command.equals("New")){
- newGame();
- }
- else if (command.equals("Save")){
- save();
- }
- else if (command.equals("Open")){
- open();
- }
- }
- public void newGame(){
- String inputValue = JOptionPane.showInputDialog("Please enter the name of the map you would like to use. (Map must already be saved in directory)");
- Icon icon = new ImageIcon(inputValue + ".png");
- final JLabel imageLabel = new JLabel(icon);
- centerPanel.add(imageLabel);
- repaint();
- try{
- File file = new File(inputValue + ".board");
- boolean success = file.createNewFile();
- if (success){}
- else {
- JOptionPane.showMessageDialog(null, "File already exists. Please try again");
- }
- }
- catch (IOException e){}
- }
- public void open(){
- String inputValue = JOptionPane.showInputDialog("Please enter the name of the board file you would like to use. (File must already be saved in directory)");
- try {
- FileReader fr = new FileReader(inputValue + ".board");
- BufferedReader br = new BufferedReader(fr);
- }
- catch(IOException e){}
- JLabel imageLabel = new JLabel();
- ImageIcon icon = new ImageIcon(inputValue + ".png");
- imageLabel.setIcon(icon);
- centerPanel.add(imageLabel);
- repaint();
- }
- public void getColor(int x, int y){
- Raster raster = bImage.getRaster();
- Object data = raster.getDataElements(x, y, null);
- ColorModel model = bImage.getColorModel();
- int rgb = model.getRGB(data);
- Color color = new Color(rgb);
- String pixel = color.toString();
- System.out.println(pixel);
- }
- public void mouseClicked(MouseEvent e) {
- getColor(e.getX(), e.getY());
- }
- public void save(){}
- public static void main(String[] args){
- RiskFrame frame = new RiskFrame();
- frame.setSize(800,800);
- frame.setVisible(true);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
Any help would be greatly appreciated. THANK YOU!!