Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Simple beginers problem

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Simple beginers problem

    I am just a beginer of java programing and i dont know what mistake i did in the code.

    //Komandu eilutes sasaja ir JoptionPane elementai
    javax.swing.JOptionPane;
    public class Labas {
    	public static void main(String args[]) {
    		String pirmas =
    			JOptionPane.ShowInputDialog("Pirma reiksme");
    String pirmas =
    			JOptionPane.ShowInputDialog("Antra reiksme");
    int skaicius1 = Integer.parseInt(pirmas);
    int skaicius2 = Integer.parseInt(antras);
    JoptionPane.ShowMessageDialog(null,
    		"Dvieju skaiciu suma" +(skaicius1 + skaicius2),
    		"Rezultatas",JOptionPane.PLAIN_MESSAGE);
    	System.exit(0); //pabaiga, naudijant grafine sasaja
    	}
    }

    I think that mistake is in 2 line but i dont no how to fix it. Please help.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,332
    My Mood
    Hungover
    Thanks
    143
    Thanked 624 Times in 535 Posts

    Default Re: Simple beginers problem

    What does the program do that you didn't expect? What doesn't it do that you did expect? What's the problem with it? Be specific. Do you get an exception? If so, post the full text of the stack trace and point out any line numbers in your code. Any weird behavior? What's weird about it?

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Simple beginers problem

    For a start, there is no import infront of javax.swing.JOptionPane;

    You have also duplicated the String variable pirmas

    JoptionPane needs to be JOptionPane

    ShowInputDialog needs to be showInputDialog

    antras is unrecognised. You need to create this variable.

    There are lots of small silly mistakes.. If you make all these changes, the code will compile without a problem.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  4. #4
    Junior Member
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple beginers problem

    I am programing it with JCreator and it shows me this error.

    C:\Documents and Settings\Vytautas\My Documents\JCreator LE\MyProjects\ObjektinisProgramavimas\LabasSuSasaj a.java:2: class, interface, or enum expected
    javax.swing.JOptionPane;
    ^
    1 error

    Process completed.

    It has to show me three dialog boxes. In first two i write numbers and program sums those numbers and shows result in the third dialog box.
    Last edited by vycka1990; November 18th, 2010 at 12:36 PM.

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Simple beginers problem

    Change javax.swing.JOptionPane; to import javax.swing.JOptionPane;
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. simple game with swing and awt problem
    By Pulse_Irl in forum AWT / Java Swing
    Replies: 2
    Last Post: October 12th, 2010, 02:04 PM
  2. Simple Actionlistener problem
    By olemagro in forum AWT / Java Swing
    Replies: 5
    Last Post: October 11th, 2010, 10:46 AM
  3. Simple import problem
    By Mekster in forum Java IDEs
    Replies: 3
    Last Post: November 13th, 2009, 08:17 PM
  4. Simple scanner problem
    By Sinensis in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: September 20th, 2009, 09:01 PM
  5. simple problem w/ appelets which i cant figure out
    By JavaGreg in forum Java Applets
    Replies: 7
    Last Post: August 15th, 2009, 07:22 PM