Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-30-2008, 02:27 AM
Member
 
Join Date: Mar 2008
Posts: 3
Jononomous is on a distinguished road
JLabel and text concept issues
Basically I want to display the output with a JLabel from the text fields where the data is entered, and when the Calculate button is pressed to display this output. Here is what I have so far but I feel I'm kind of off track a bit.

###################



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class TextFrame extends JFrame implements ActionListener{

private static final int FRAME_WIDTH = 300;
private static final int FRAME_HEIGHT = 200;
private static final int FRAME_X_ORIGIN = 150;
private static final int FRAME_Y_ORIGIN = 250;

private static final int BUTTON_WIDTH = 80;
private static final int BUTTON_HEIGHT = 30;

private static final double SHIPPING = 0.12;

private JButton calculateTotal;
private JLabel prompt;
private JLabel prompt2;
private JLabel display;
private JLabel display2;

private JTextField inputLine;
private JTextField inputLine2;
private JTextField inputLine3;

public static void main(String[] args) {

TextFrame frame = new TextFrame();
frame.setVisible(true);

}

public TextFrame() {


Container contentPane;

setSize(FRAME_WIDTH, FRAME_HEIGHT);
setResizable(false);
setTitle("Project");
setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);

contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());

prompt = new JLabel( );
prompt.setText("Enter ID Code: ");
prompt.setSize(150,25);
contentPane.add(prompt);

inputLine = new JTextField( );
inputLine.setColumns(10);
contentPane.add(inputLine);

prompt2 = new JLabel( );
prompt2.setText("Weight: Pounds | Ounces: ");
prompt2.setSize(150,25);
contentPane.add(prompt2);

inputLine2 = new JTextField( );
inputLine2.setColumns(5);
contentPane.add(inputLine2);

inputLine3 = new JTextField( );
inputLine3.setColumns(5);
contentPane.add(inputLine3);

inputLine.addActionListener(this);
inputLine2.addActionListener(this);
inputLine3.addActionListener(this);

calculateTotal = new JButton("Calculate");
calculateTotal.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(calculateTotal);

display = new JLabel( );
display.setText(" ID Weight Shipping Charge ");
display.setSize(150,25);
contentPane.add(display);

String idcode = inputLine.getText();
String pounds = inputLine2.getText();
String ounces = inputLine3.getText();

display2 = new JLabel( );
display2.setText(idcode);
display2.setSize(150,25);
contentPane.add(display2);



calculateTotal.addActionListener(this);

setDefaultCloseOperation(EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent event) {


if (event.getSource() instanceof JButton) {
JButton clickedButton = (JButton) event.getSource();




} else {
setTitle("You entered '" + inputLine.getText() + "'");
}


}



}



Any Help would be very much appreciated.

Thanks,

- GoOsE
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-30-2008, 06:42 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
Code:
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TF extends JFrame implements ActionListener { private static final int FRAME_WIDTH = 300; private static final int FRAME_HEIGHT = 200; private static final int FRAME_X_ORIGIN = 150; private static final int FRAME_Y_ORIGIN = 250; private static final int BUTTON_WIDTH = 80; private static final int BUTTON_HEIGHT = 30; private static final double SHIPPING = 0.12; private JButton calculateTotal; private JLabel prompt; private JLabel prompt2; private JLabel display; private JLabel display2; private JTextField inputLine; private JTextField inputLine2; private JTextField inputLine3; public static void main(String[] args) { TF frame = new TF(); frame.setVisible(true); } public TF() { Container contentPane; setSize(FRAME_WIDTH, FRAME_HEIGHT); setResizable(false); setTitle("Project"); setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN); contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); prompt = new JLabel( ); prompt.setText("Enter ID Code: "); prompt.setSize(150,25); contentPane.add(prompt); inputLine = new JTextField( ); inputLine.setColumns(10); contentPane.add(inputLine); prompt2 = new JLabel( ); prompt2.setText("Weight: Pounds | Ounces: "); prompt2.setSize(150,25); contentPane.add(prompt2); inputLine2 = new JTextField( ); inputLine2.setColumns(5); contentPane.add(inputLine2); inputLine3 = new JTextField( ); inputLine3.setColumns(5); contentPane.add(inputLine3); inputLine.addActionListener(this); inputLine2.addActionListener(this); inputLine3.addActionListener(this); calculateTotal = new JButton("Calculate"); calculateTotal.setSize(BUTTON_WIDTH, BUTTON_HEIGHT); contentPane.add(calculateTotal); display = new JLabel( ); display.setText(" ID Weight Shipping Charge "); display.setSize(150,25); contentPane.add(display); // String idcode = inputLine.getText(); // String pounds = inputLine2.getText(); // String ounces = inputLine3.getText(); display2 = new JLabel( ); // display2.setText(idcode); display2.setSize(150,25); contentPane.add(display2); calculateTotal.addActionListener(this); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent event) { // If this is all you're going to do in this method then // you don't need to find out which component sent the event. // You can do this for any event received: String idcode = inputLine.getText(); String pounds = inputLine2.getText(); String ounces = inputLine3.getText(); String s = "ID Code: " + idcode + ", " + pounds + " pounds " + ounces + " ounces"; display2.setText(s); // if (event.getSource() instanceof JButton) { // JButton clickedButton = (JButton) event.getSource(); // } else { // setTitle("You entered '" + inputLine.getText() + "'"); // } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
mail concept indirani New To Java 3 04-16-2008 02:30 PM
mail concept thamizhisai Advanced Java 4 04-11-2008 08:19 AM
What is RMI concept in Spring Framework Java Tip Spring Framework 0 04-02-2008 11:36 AM
JLabel Jack AWT / Swing 2 07-02-2007 02:55 PM
JLabel Freddie AWT / Swing 2 05-29-2007 03:19 PM


All times are GMT +3. The time now is 09:10 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org