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

[352 byte] By [thehurricanea] at [2007-11-27 2:13:12]
# 1
Here is some punctuation. I suggest you salt and pepper your message with it:.....,,,,,;;?!!
DrLaszloJamfa at 2007-7-12 2:08:29 > top of Java-index,Java Essentials,New To Java...
# 2
JTEXTAREA
mkoryaka at 2007-7-12 2:08:29 > top of Java-index,Java Essentials,New To Java...
# 3
hth, not sure if this is what you were looking forJTextField myField = new JTextField();//other stuff......myField.setText("Select a movie to buy");
cafBeana at 2007-7-12 2:08:29 > top of Java-index,Java Essentials,New To Java...
# 4

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");

}

}}

thehurricanea at 2007-7-12 2:08:29 > top of Java-index,Java Essentials,New To Java...
# 5

<html>

<head>

<title>VideoStore</title>

</head>

<body>

<center>Our First Applet with Swing

<applet code= "VideoStore.class" width="250" height="200" >

</applet>

</center>

</body>

</html>

thats my Html file if anyone wants to run my program but when u see it run u'll notice that theirs 3 buttons u can click on its a movie program and whatever Jbutton u click on it displays a movie I wanna know how u make the box below default the words "select a movie to buy"

the last code posted didnt work

Message was edited by:

thehurricane

thehurricanea at 2007-7-12 2:08:29 > top of Java-index,Java Essentials,New To Java...
# 6

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");

}

}}

Michael_Dunna at 2007-7-12 2:08:29 > top of Java-index,Java Essentials,New To Java...