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 2 of 2

Thread: GUI html problem

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default GUI html problem

    Hello,

    I am working on a GUI unit project and I have run into a problem. When I run the program in my browser as an .html file, I get an error saying "Error. Click for details."
    When I click, I get a message box that says "java.lang.reflect.InvocationTargetException" My program compiled fine, so I don't know what the problem is. When I try running the .java file in the JDK, I get a window that only contains the last button that I added to the frame. I have attached the .java code. I would appreciate any guidance.

    [QUOTE][/import javax.swing.*;
    class guip
    {
    private static void create()
    {
    JFrame frame1 = new JFrame("GUI Project Applet");
    frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE);

    JLabel label1 = new JLabel("This applet is for the GUI Unit Project");


    JTextField tf1 = new JTextField("Please enter your first name:");
    JTextField tf2 = new JTextField("Please enter your last name:");
    JTextField tf3 = new JTextField("Please enter your favorite color:");
    JTextField tf4 = new JTextField("Please enter your favorite hobby:");
    JTextField tf5 = new JTextField("Please enter your time zone:");

    JButton button1 = new JButton("OK");
    JButton button2 = new JButton("CANCEL");
    frame1.getContentPane().add(label1);
    frame1.add(tf1);
    frame1.add(tf2);
    frame1.add(tf3);
    frame1.add(tf4);
    frame1.add(tf5);
    frame1.add(button1);
    frame1.add(button2);
    frame1.pack();
    frame1.setVisible(true);
    }

    }QUOTE]


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: GUI html problem

    First, use a Layout manager and don't just dump stuff into the JFrame. Run it from the EDT.
    Use code tags whem posting code.
    Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    Using Top-Level Containers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

Similar Threads

  1. Streaming data to html problem
    By adec in forum Java Servlet
    Replies: 2
    Last Post: February 13th, 2012, 08:29 AM
  2. Problem to get info from HTML file
    By zecute in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 19th, 2011, 04:57 AM
  3. GUI problem
    By Reem in forum AWT / Java Swing
    Replies: 6
    Last Post: November 15th, 2010, 09:45 AM
  4. Javamail html mail sended as text and headers problem
    By johnymj in forum What's Wrong With My Code?
    Replies: 0
    Last Post: July 29th, 2010, 09:22 AM
  5. GUI Problem
    By bulldog in forum AWT / Java Swing
    Replies: 1
    Last Post: December 11th, 2009, 01:47 PM

Tags for this Thread