this is my code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MainClass extends JFrame implements ActionListener
{
MainClass()
{
}
//components
static JLabel lbl = new JLabel("Enter you ID number:");
static TextField tf = new TextField(50);
static JButton sub = new JButton("Submit");
static JLabel prompt = new JLabel("What do you want to do?");
static JButton grades = new JButton("View Grades");
static JButton evals = new JButton("View Evaluation");
//object of the JFrame class
static MainClass mc;
public static void main(String args[])
{
mc = new MainClass();
mc.setVisible(true);
mc.setSize(500, 150);
mc.setLocation(50, 50);
mc.setResizable(false);
mc.setLayout(new FlowLayout());
mc.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
sub.addActionListener(mc);
grades.addActionListener(mc);
sub.addActionListener(mc);
mc.add(lbl);
mc.add(tf);
mc.add(sub);
mc.add(prompt);
mc.add(grades);
mc.add(evals);
prompt.setEnabled(false);
grades.setEnabled(false);
evals.setEnabled(false);
}
public void actionPerformed(ActionEvent ae)
{
Object o = ae.getSource();
if(o==sub)
{
lbl.setEnabled(false);
tf.setEnabled(false);
sub.setEnabled(false);
prompt.setEnabled(true);
grades.setEnabled(true);
evals.setEnabled(true);
}
else if(o==grades)
{
prompt.setEnabled(false);
grades.setEnabled(false);
evals.setEnabled(false);
Grades gp = new Grades();
mc.getContentPane().add(gp);
}
else if(o==evals)
{
prompt.setEnabled(false);
grades.setEnabled(false);
evals.setEnabled(false);
Evals ev = new Evals();
mc.getContentPane().add(ev);
}
}
}
// here are the external classes in separate files
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Grades extends JPanel
{
public Grades()
{
add(new JLabel("Your grade is 95"));
//some other components
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Evals extends JPanel
{
public Evals()
{
add(new JLabel("Your standing: A+"));
//some other components
}
}
On Aug 3, 2:31 pm, Lester Guerzon <[email protected]> wrote:
> guys,
>
> i have a Frame with two buttons, Button b1 and Button b2. If i click
> b1, a Label would be added into the Frame. If the user clicks b2, a
> TextField would be added instead.
>
> i was trying to do frame.add() but it's not working.
>
> what should i do?
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---