import javax.swing.*; import java.awt.*; import java.awt.event.*; public class CollageMakerSkeleton { private static int x, y, size, choice; // choice will tell GraphicsPanel what button was clicked, x, y, size will tell private static String name; // GraphicsPanel where to put the image, name is the file's name private static GraphicsPanel gp2; // we need gp2 here since we will call gp2.repaint() from gp1 public static void main(String[] args) { JFrame f=new JFrame(); f.setSize(1000,1000); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GUIPanel gp1=new GUIPanel(); // we declare gp1 here since we don't use gp1 anywhere else in the code gp2=new GraphicsPanel(); // instantiate gp2 (notice we declared it above) JPanel temp=new JPanel(new BorderLayout()); // BorderLayout will give us the best layout for this GUI temp.add(gp1,BorderLayout.NORTH); temp.add(gp2,BorderLayout.CENTER); f.add(temp); f.setVisible(true); choice=-1; // initialize choice to something not used in GraphicsPanel } public static class GUIPanel extends JPanel implements ActionListener { // declare as Private 4 JTextFields and 3 JButtons public GUIPanel() { // declare and instantiate 4 JLabels to describe the 4 JTextField inputs: filename, x, y, size // instantiate the 4 JTextFields, for filename, make it ("",15) to make it longer, the others can be ("",3) or ("",4) // instantiate the 3 JButtons // add the action listeners to each JButton // Create 4 JPanels, in the first, add the filename JLabel and JTextField // in the second, add the other 3 JLabels and JTextFields side-by-side (JLabel JTextfield JLabel JTextField JLabel JTextField) // in the third add the 3 JButtons in one row // In the 4th, use GridLayout(3,1) and add the first 3 JPanels // finally, do add(fourth JPanel) as in add(jp4); } public void actionPerformed(ActionEvent e) { // determine what button was pressed using code like // if(e.getActionCommand().equals("Load Image")) // if it was the load image JButton, get the x, y, size values and the filename from the JTextFields - don't forget that // you need to use Integer.parseInt(field.getText()); if the field is going to be treated as a number (x, y, size) // next, reset that field's text to "", for instance field.setText(""); // set choice to 1 and then call gp2.repaint(); to repaint the graphics panel // if it was the clear, set choice to 2 and then call gp2.repaint(); // if it was quit, do System.exit(0); } } public static class GraphicsPanel extends JPanel { public void paintComponent(Graphics g) { // if choice is 1, get the image using the filename (name) and then do g.drawImage // if choice is 2, do super.paintComponent(g); // reset choice to -1 } } }