JTEXTFIELD
I created a JTextFeild and would like to know how u make it so by default it reads the words select a movie to buy my program is a online movie buyier and by clicking on Jbuttons the Text appears for whatever you bought all I wanna know is how do u make it so before u even click a button how would I go about making it say Select a movie to buy
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class VideoStore extends JApplet implements ActionListener{
Container con = getContentPane();
JLabel CCAC = new JLabel("CCAC Video Store");
Font headlineFont = new Font ("TimesRoman", Font.BOLD, 24);
JLabel Family = new JLabel("Johnsons Family Vacation");
Fontfamily = new Font ("Courier", Font.BOLD, 14);
JLabel Black = new JLabel("Pitch Black ");
Font black = new Font ("Courier", Font.BOLD, 14);
JLabel Folkers = new JLabel("Meet the Folkers");
Font folkers = new Font ("Courier", Font.BOLD, 14);
JButton b1, b2, b3;
JTextField display;
private JTextField t1;
public void init() {
FlowLayout flow = new FlowLayout();
setLayout(flow);
b1 = new JButton ("Buy");
b2 = new JButton ("Buy");
b3 = new JButton ("Buy");
display = new JTextField(20);
display.setEditable(false);
display.setHorizontalAlignment(JTextField.LEFT);
setLayout(new FlowLayout());
CCAC.setFont(headlineFont);
con.add(CCAC);
Family.setFont(family);
con.add(Family);
add(Family);
add(b1);
Black.setFont(black);
con.add(Black);
add(Black);
add(b2);
Folkers.setFont(folkers);
con.add(Folkers);
add(Folkers);
add(b3);
add(display);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == b1) {
display.setText("Johnson Family Vacation");
}
else if(e.getSource() == b2) {
display.setText("Pitch Black");
}
else if(e.getSource() == b3) {
display.setText("Meet The Folkers");
}
}}
try these changes - should work OK regardless of size (250,200 or 800,600 etc)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TestApplet extends JApplet implements ActionListener{
//Container con = getContentPane();
JPanel con = new JPanel(new BorderLayout());
//JLabel CCAC = new JLabel("CCAC Video Store");
JLabel CCAC = new JLabel("CCAC Video Store",JLabel.CENTER);
Font headlineFont = new Font ("TimesRoman", Font.BOLD, 24);
JLabel Family = new JLabel("Johnsons Family Vacation");
Fontfamily = new Font ("Courier", Font.BOLD, 14);
JLabel Black = new JLabel("Pitch Black ");
Font black = new Font ("Courier", Font.BOLD, 14);
JLabel Folkers = new JLabel("Meet the Folkers");
Font folkers = new Font ("Courier", Font.BOLD, 14);
JButton b1, b2, b3;
JTextField display;
private JTextField t1;
public void init() {
//FlowLayout flow = new FlowLayout();
//setLayout(flow);
setLayout(new GridBagLayout());
JPanel p = new JPanel(new GridLayout(3,2));
b1 = new JButton ("Buy");
b2 = new JButton ("Buy");
b3 = new JButton ("Buy");
display = new JTextField(20);
display.setEditable(false);
display.setHorizontalAlignment(JTextField.LEFT);
p.add(Family);
JPanel pb1 = new JPanel();
pb1.add(b1);
p.add(pb1);
p.add(Black);
JPanel pb2 = new JPanel();
pb2.add(b2);
p.add(pb2);
p.add(Folkers);
JPanel pb3 = new JPanel();
pb3.add(b3);
p.add(pb3);
JPanel p1 = new JPanel(new GridLayout(2,1));
p1.add(display);
p1.add(new JLabel("select a movie to buy",JLabel.CENTER));
//setLayout(new FlowLayout());
CCAC.setFont(headlineFont);
//con.add(CCAC);
Family.setFont(family);
//con.add(Family);
//add(Family);
//add(b1);
Black.setFont(black);
//con.add(Black);
//add(Black);
//add(b2);
Folkers.setFont(folkers);
//con.add(Folkers);
//add(Folkers);
//add(b3);
//add(display);
con.add(CCAC,BorderLayout.NORTH);
con.add(p,BorderLayout.CENTER);
con.add(p1,BorderLayout.SOUTH);
add(con,new GridBagConstraints());
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == b1) {
display.setText("Johnson Family Vacation");
}
else if(e.getSource() == b2) {
display.setText("Pitch Black");
}
else if(e.getSource() == b3) {
display.setText("Meet The Folkers");
}
}}