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

Thread: Java Noob, Jframe in Applet.

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Noob, Jframe in Applet.

    Hi guys im stuck. i need to make a java applet but within a jframe, I've pretty much got it working without a jframe but i can't figure out how to add it in.
    Heres my code.

    import javax.swing.*;
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.util.Arrays;
    import javax.swing.JFrame;
    public class Gui extends Applet 
    {
     
         Button okButton;
         Button clearButton;
     
         JTextField usernameField;
         JPasswordField passwordField;
     
         public void init()
         {
     
            setLayout(null);
     
            okButton = new Button("Submit");
            clearButton = new Button("Reset");
     
            usernameField = new JTextField("",100);
            passwordField = new JPasswordField("",100);
     
              clearButton.setBounds(160,80,100,30);
              okButton.setBounds(50,80,100,30);
              usernameField.setBounds(110,9,200,20);
              passwordField.setBounds(110,39,200,20);
     
     
          add(clearButton);
          add(okButton);
          add(usernameField);
          add(passwordField);
         }
        public void paint(Graphics g) 
        {   
            g.setColor(Color.BLACK);
            g.drawString("Enter Username:",10,20);
            g.drawString("Enter Password:",10,55);
        }
        }
    So yeah if you could explain what im suppose to do, it will be much appreciated.
    Last edited by rLLZORS; May 4th, 2011 at 03:23 PM.


  2. #2
    Junior Member
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Noob, Jframe in Applet.

    Thanks for your help guys, i figured it out. In case anyone actually needs help heres my code.

     
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.JApplet;
    public class applet extends JApplet
    {
        private JFrame aFrame;
        private JTextField aText;
        private JTextField bText;
        private JLabel aLabel;
        private JLabel bLabel;
        private JButton aButton;
        private JButton bButton;
        private Container aBox;
        private Container bBox;
        public void init()
        {
            setLayout(null);
            aBox = this.getContentPane();
            aLabel = new JLabel("Username:");
            aText = new JTextField(10);
            bLabel = new JLabel("Password:");
            bText = new JPasswordField(10);
            aButton = new JButton("Reset");
            bButton = new JButton("Submit");
     
            aButton.addActionListener(new ActionListener()
            {
               public void actionPerformed(ActionEvent e)
               {
                  aText.setText("");
                  bText.setText("");
               }
            });
     
            bButton.addActionListener(new ActionListener()
            {
               public void actionPerformed(ActionEvent e)
               {
                  aText.setText("");
                  bText.setText("");
               }
            });
     
     
            add(aLabel);
            aLabel.setBounds(10,11,100,11);
            add(bLabel);
            bLabel.setBounds(10,35,100,35);
            add(aText);
            aText.setBounds(110,9,200,20);
            add(bText);
            bText.setBounds(110,39,200,20);
            add(aButton);
            aButton.setBounds(50,80,100,30);
            add(bButton);
            bButton.setBounds(160,80,100,30);
     
     
        }
        }

  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: Java Noob, Jframe in Applet.

    Hello rLLZORS.

    Welcome to the Java Programming Forums.

    Sorry I didn't get a chance to reply to this thread sooner. I am glad you have worked out your issues..

    I will mark this thread as solved.
    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. Noob that needs some clearing up with Java style programming
    By looneylu in forum Java Theory & Questions
    Replies: 3
    Last Post: January 23rd, 2011, 10:27 PM
  2. Programming noob here, need help!
    By artenuga54 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 18th, 2010, 04:04 PM
  3. helloworld noob
    By LostFury2012 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: July 14th, 2010, 06:29 AM
  4. Java Gif image problem in JFrame
    By Zachary Wins in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 23rd, 2010, 08:51 PM
  5. Need Help with my hmwk! Java noob!
    By ravij in forum Loops & Control Statements
    Replies: 4
    Last Post: October 7th, 2009, 01:02 AM