Results 1 to 4 of 4
- 03-24-2012, 07:04 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 4
- Rep Power
- 0
JAVA HELP URGENT ! problem with text box dollar sign
Hi. 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, how do i add the $ sign when display the price charge.
the ouput should be like this:
Fee Calculator
ID Code: [Text Box]
Weight: [Text Box]
Rate: [$1.02]
Price Charge: [$ ]
my 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 scrollbars 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_C LOSE);
}//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);
//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 textfields and calculate and display the gross pay
public void addPerformed(ActionEvent evt)
{
double Weight = 0,Rate,priceCharge;
Rate = 0.12;
priceCharge = (Weight * Rate);
}
}//end of class
- 03-24-2012, 07:22 AM #2
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Re: JAVA HELP URGENT ! problem with text box dollar sign
You didn't add the TextFields to the mainPanel that's why they are not showing up. I would say you should use a layout manager. As far as the dollar sign one way would be to declare a String Variable like :
Java Code:String sign = "$"; String.Format("%s%2d", sign, priceCharge);
- 03-24-2012, 07:59 AM #3
Member
- Join Date
- Mar 2012
- Posts
- 4
- Rep Power
- 0
Re: JAVA HELP URGENT ! problem with text box dollar sign
Sorry new to java. Didn't I added the TextFields under the mainPanel? Can you give me more information. Thank You.
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);
- 03-24-2012, 08:44 AM #4
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Re: JAVA HELP URGENT ! problem with text box dollar sign
you added some of your components here is what you added:
Java Code:mainPanel.add(label1); mainPanel.add(IDcode); mainPanel.add(Weight); mainPanel.add(Rate); mainPanel.add(priceCharge); mainPanel.add(calculateButton); mainPanel.add(outputScrollPane);
Java Code:JTextField IDCodeField = new JTextField(20); JTextField WeighttField = new JTextField(20); JTextField RatetField = new JTextField(20);
Java Code:mainPanel.add(IDCodeField); etc........
start here:Using Layout Managers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
Similar Threads
-
Problem using the pound sterling sign (£)
By sarni13 in forum New To JavaReplies: 3Last Post: 04-28-2011, 03:14 PM -
Dollar sign and DecimalFormat
By javauserjava in forum New To JavaReplies: 7Last Post: 04-06-2011, 12:57 AM -
Dollar sign in a while statement
By oneprotect in forum Advanced JavaReplies: 3Last Post: 01-18-2011, 12:01 PM -
problem sending Dollar symbol in SMS
By neerajsaxena in forum Advanced JavaReplies: 1Last Post: 01-28-2010, 07:37 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 08:35 AM
Bookmarks