Results 1 to 4 of 4
- 08-07-2010, 05:19 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 2
- Rep Power
- 0
JFrame - Output and Input in Frame - menu choice and simple Calculator
Okay so i have 2 Java files
Java Main Class - "Main.java"
and
Java Class - "frame.java"
these java files are in the same folder and project called "menuchoice"
Basically what i want to happen is have a JFrame window and have all the input and output code that comes with the calculator and menuchoice happen in the JFrame and not in the IDE NetBeans Run Window
Inside frame.java
// this is the frame set up java file
Java Code:package menuchoice; import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JLabel; public class frame extends JFrame{ private JLabel item1; public frame(){ super("The Title Bar"); setLayout(new FlowLayout()); item1 = new JLabel("This Is The Label"); item1.setToolTipText("This Is Show On Hover"); add(item1); } }
Inside Main.java
// this is the file that contains the menu + calculator code.
Picture of what currently is happening and what i would like to happen.Java Code:package menuchoice; import javax.swing.JFrame; import java.util.Scanner; public class Main { public static void main(String[] args) { frame oneframe = new frame(); oneframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); oneframe.setSize(275,180); oneframe.setVisible(true); Scanner choice = new Scanner(System.in);{ double menuselect; System.out.println("Please Enter the Number\n1. Addition\n2. Subtraction"); menuselect = choice.nextDouble(); if (menuselect == 1){ Scanner addidtion = new Scanner(System.in); double fnum, snum, answer; System.out.println("Enter first number: "); fnum = addidtion.nextDouble(); System.out.println("Enter second number: "); snum = addidtion.nextDouble(); answer = fnum + snum; System.out.println(answer); } if (menuselect == 2){ Scanner subtraction = new Scanner(System.in); double fnum, snum, answer; System.out.println("Enter first number: "); fnum = subtraction.nextDouble(); System.out.println("Enter second number "); snum = subtraction.nextDouble(); answer = fnum - snum; System.out.println(answer);} else{ System.out.println("Error: Enter a valid menu choice");} } } }

Thanks a lot guys any help/tips would be much appreciated, ive tried a few things but can figure it out.Last edited by Fubarable; 08-07-2010 at 05:21 AM. Reason: Moderator Edit: Bold tags changed to Code tags for readability
-
Moderator edit: bold tags exchanged for code tags to aid readability. To the OP, to see how to use code tags, please click on the related link in my signature.
-
You really can't just move a console app to a GUI like you're trying to do. Well, you can, sort of, but it's ugly and kludgy. Part of the issue is that GUI applications don't just look different from console code, they are very different to the core since gui programs are event-driven while console programs are usually much more linear. What would be better is to read up on and learn how to create Swing apps from scratch, and you are interested, you should start here: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
Much luck and welcome!Last edited by Fubarable; 08-07-2010 at 05:28 AM.
- 08-07-2010, 05:28 AM #4
Member
- Join Date
- Aug 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
creating a simple calculator
By hobo in forum New To JavaReplies: 4Last Post: 11-09-2009, 03:09 AM -
Simple Calculator Display Problem :(
By jimbob in forum Java AppletsReplies: 4Last Post: 07-18-2009, 04:13 AM -
[SOLVED] Simple Conversion Calculator
By dbashby in forum New To JavaReplies: 6Last Post: 03-20-2009, 01:06 AM -
Sending output to a Frame
By Java Tip in forum Java TipReplies: 0Last Post: 02-04-2008, 09:28 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks