After they select the number of images it asks for the name of the images (I haven't coded that part yet). The problem is that when I execute the program all it does it load up the input dialog for me to enter the number of images, and then lets say I put in "3", it just completes the Process, it never launches the GUI window.
Here is my code so far:
Main GUI Class
Code: Select all
import javax.swing.*;
import java.awt.*;
import javax.swing.JOptionPane;
public class Images{
public static void main(String[] args){
int num = 0;
String inputstr = JOptionPane.showInputDialog("Enter number of panels:", "0");
if (inputstr != null){
if(inputstr == "1") num = 1;
else if(inputstr == "2") num = 2;
else if(inputstr == "3") num = 3;
else if(inputstr == "4") num = 4;
JFrame theGUI = new JFrame();
theGUI.setTitle("Example 6.7");
theGUI.setSize(300, 200);
theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container pane = theGUI.getContentPane();
pane.setLayout(new GridLayout(num, num));
for (int count = 1; count <= num; count++){
//I haven't changed the ColorPanel class to load in images yet
ColorPanel panel = new ColorPanel(Color.white);
pane.add(panel);
}
theGUI.setVisible(true);
}
}
}
ColorPanel Class
Code: Select all
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ColorPanel extends JPanel{
public ColorPanel(Color backColor){
setBackground(backColor);
}
}
Help please.