1 Attachment(s)
Need help putting GUI in program!
I have a program that works fine already, I just have to make a GUI for it and have no idea what I am doing lol. I need it to look like the picture I have attached. Can anyone please help! Much appreciated!
Code Java:
import java.io.PrintStream;
import javax.swing.JOptionPane;
public class DivisibleByTwo
{
public static void main(String args[])
{
int first = Integer.parseInt(JOptionPane.showInputDialog("Enter starting integer."));
int second = Integer.parseInt(JOptionPane.showInputDialog("Enter ending integer."));
if(first > second)
{
int temp = first;
first = second;
second = temp;
}
System.out.println((new StringBuilder()).append("The integers divisible by 2 in the range ").append(first).append(" to ").append(second).append(" are:\n").toString());
for(int l = first; l <= second; l++)
if(l % 2 == 0)
System.out.printf("\t\t%5d\n", new Object[] {
Integer.valueOf(l)
});
System.exit(0);
}
}
Re: Need help putting GUI in program!
Re: Need help putting GUI in program!
I have a basic understanding of creating a GUI but Im having a real hard time turning an already made program into one that has a GUI. Any help please?
Re: Need help putting GUI in program!
Quote:
I have a basic understanding of creating a GUI
Then what have you tried? Did you try to create a JFrame with a layout similar to the picture you attached? That's one place where you can start...
Re: Need help putting GUI in program!
I have to put "extends JFrame
implements ActionListener" in right? But do I put it right after "public class DivisibleByTwo" or what? I'm just having trouble incorporating the gui stuff into the code I already have. Thanks
Re: Need help putting GUI in program!
Quote:
Originally Posted by
greyfox175
I have to put "extends JFrame
implements ActionListener" in right? But do I put it right after "public class DivisibleByTwo" or what? I'm just having trouble incorporating the gui stuff into the code I already have. Thanks
This means you should go back and read the tutorial I linked above - it might seem overwhelming but if you search you will find the components you need, and tutorials showing you how to use them. My advice: start from scratch and break your problem down - strip out the logic from your original code and turn it into a method which can be accessed regardless of whether you use the command line, a gui, whatever (this is a very important concept to learn). Then write your GUI - as I said break the problem down - first work on the layout, then work on the Actions, then work on linking those actions to the logic