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.
Code Java:
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.
Re: Java Noob, Jframe in Applet.
Thanks for your help guys, i figured it out. In case anyone actually needs help heres my code.
Code Java:
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);
}
}
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.