Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
Due to network maintenance being performed by our provider, LQ will be down starting at 05:01 AM UTC. The exact duration of the downtime isn't currently known. We apologize for the inconvenience.
|
 |
03-24-2012, 09:21 PM
|
#1
|
|
LQ Newbie
Registered: Mar 2012
Posts: 2
Rep: 
|
JAVA text boxes does not show
hi guys. I am new to java and I have problems with my java codes. I have problem adding text box after each label ID Code, Weight, Rate, Price Charge, it does not show when i run the code. Also, I am trying to make the prceCharge field to display the amount with the dollar sign in the box, not sure if the code is right.
the ouput should be like this:
Fee Calculator
ID Code: [Text Box]
Weight: [Text Box]
Rate: [$1.02]
Price Charge: [$ ]
Code:
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*; //Needed for swing components
public class PayrollApplication extends JFrame
implements ActionListener
{
//declare your instance objects here
JPanel mainPanel = new JPanel();
JLabel label1 = new JLabel("Fee Calculator");
JLabel IDcode = new JLabel("ID Code: ");
JLabel Weight = new JLabel ("Weight: ");
JLabel Rate = new JLabel ("Rate: ");
JLabel priceCharge = new JLabel ("Price Charge: ");
JTextField label1Field = new JTextField(20);
JTextField IDCodeField = new JTextField(20);
JTextField WeighttField = new JTextField(20);
JTextField RatetField = new JTextField(20);
JTextField PricetField = new JTextField(20);
JButton calculateButton = new JButton("Calculate Shipping Fee");
JTextArea outputTextArea = new JTextArea(5, 20);
JScrollPane outputScrollPane = new JScrollPane(outputTextArea); //For scroll bars around text area
Font bigFont = new Font("Times New Roman", Font.BOLD, 28);
// This is the first method called in a application
//We will create an object of ourselves to call the
//constructor and then set the default close operation for the frame
public static void main(String[] args)
{
PayrollApplication basicGUI = new PayrollApplication();
basicGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}//end of main
//This is the constructor for this class. It will be called from main
//It will set up our GUI panel with needed components
//and set up appropriate event listening
public PayrollApplication()
{
//call the superclass' constructor and send a title
super("Fee Calculator");
//add GUI components to the appropriate container
mainPanel.add(label1);
label1.setFont(bigFont);
label1.setForeground(Color.RED);
mainPanel.add(IDcode);
mainPanel.add(Weight);
mainPanel.add(Rate);
mainPanel.add(priceCharge);
mainPanel.add(calculateButton);
mainPanel.add(outputScrollPane);
JTextField IDCodeField = new JTextField(20);
JTextField WeighttField = new JTextField(20);
JTextField RatetField = new JTextField(20);
JTextField priceChargetField = new JTextField(20);
//add the JPanel to the JFrame
add(mainPanel);
//call the listener method
addListeners();
//set the properties of the JFrame for display
this.setSize(300, 500);
this.setVisible(true);
}//end of constructor
//use to register the components to the action listener
public void addListeners()
{
calculateButton.addActionListener(this);
}
//Retrieve and convert text fields and calculate and display the gross pay
public void addPerformed(ActionEvent evt)
{
double Weight = 0,Rate,priceCharge;
Rate = 0.12;
priceCharge = (Weight * Rate);
String sign = "$";
String.format("%s%2d", sign, Rate, priceCharge);
}
}//end of class
|
|
|
|
03-25-2012, 09:17 AM
|
#2
|
|
Moderator
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,471
Rep: 
|
It is a homework question, so we will only help you to find the answer yourself. Do no expect direct answers, the homeworks are there to teach you something.
For your missing elements, take one of the ones that does show and one of the ones that doesn't. Compare all places in the code when they appear.
|
|
|
|
03-25-2012, 02:32 PM
|
#3
|
|
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,386
|
These declarations within your constructor overwrite those declared as class members:
Code:
public PayrollApplication()
{
...
JTextField IDCodeField = new JTextField(20);
JTextField WeighttField = new JTextField(20);
JTextField RatetField = new JTextField(20);
JTextField priceChargetField = new JTextField(20);
...
Also, you will need to add these JTextFields to the JFrame, or better yet, add both the JLabel and JTextFields to a JPanel, and then add this JPanel to the JFrame.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:01 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|