April 26th, 2002, 03:02 AM
-
cannot resolve symbol JTextField
hi all,
below is my code, which, as you can see, opens a window with two text boxes (which contain numbers) and two buttons. the first "Submit" button allows the user confirm that he is ready to update. When he clicks the "Submit" button a new instance of the stockPrice class is created
The second button, "Increase" activates a percentage increase for the numers. THis percentage increase is input using an input dialog box... ... the appropriate methods of the stockPrice class are called and the updated prices are displayed in the appropriate text boxes.
error messages i just dont understand,,, especially with the JTextFields
please help anyone.... no matter what i do i just cant get it right
CODE:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class stockPrice
{
private String stockCode;
private double costPrice;
private double sellingPrice;
double grossProfit, rate, dealerPrice;
public stockPrice(String sCode, double cPrice, double sPrice)
{
stockCode = sCode;
costPrice = cPrice;
sellingPrice = sPrice;
}
public stockPrice(String sCode, double cPrice)
{
stockCode = sCode;
costPrice = cPrice;
sellingPrice = (0.30 * costPrice) + costPrice;
}
public String getStockCode()
{
return stockCode;
}
public double getCostPrice()
{
return costPrice;
}
public double getSellingPrice()
{
return sellingPrice;
}
public void setCostPrice(double cPrice)
{
costPrice = cPrice;
}
public void setSellingPrice(double sPrice)
{
sellingPrice = sPrice;
}
public void incPrices(double rate)
{
costPrice = costPrice + (rate * costPrice);
sellingPrice = sellingPrice + (rate * sellingPrice);
}
public double grossProfit()
{
grossProfit = sellingPrice - costPrice;
return grossProfit;
}
}
public class Ex17_A
{
public static void main(String[] args)
{
JFrame Exercise17_B = new EgWindow();
Exercise17_B.show();
}
}
class EgWindow extends JFrame implements ActionListener
{
double rate, costPrice, sellingPrice;
String stockCode;
stockPrice testStockPrice = new stockPrice("PC", 100, 120);
JTextField cPriceTF = new JTextField(testStockPrice.getCostPrice(),10);
JTextField sPriceTF = new JTextField(testStockPrice.getSellingPrice(),10);
public EgWindow()
{
setTitle("Exercise 17_B");
setSize(500,500);
Container Contents=getContentPane();
JLabel Label1 = new JLabel("Stock Code: ");
JLabel Label2 = new JLabel("Cost Price: ");
JPanel InfoPanel = new JPanel();
InfoPanel.add(Label1);
InfoPanel.add(cPriceTF);
InfoPanel.add(Label2);
InfoPanel.add(sPriceTF);
JButton PIButton = new JButton("Increase");
PIButton.addActionListener(this);
JButton SButton = new JButton("Submit");
SButton.addActionListener(this);
JPanel BPanel = new JPanel();
BPanel.add(SButton);
BPanel.add(PIButton);
Contents.add(InfoPanel,"North");
Contents.add(BPanel,"Center");
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("Submit")) actSubmit();
else if (e.getActionCommand().equals("Increase")) actIncrease();
}
public void actSubmit()
{
testStockPrice = new stockPrice(cPriceTF.getText(), sPriceTF.getText());
}
public void actIncrease()
{
rate=Double.parseDouble(JOptionPane.showInputDialog("Please enter the rate:"));
}
}
April 26th, 2002, 08:58 AM
-
hi,
the error was due to the wrong value passed in the constructor...u shud pass a string....
try replacin this code in the EgWindow class...
JTextField cPriceTF = new JTextField(String.valudOf(testStockPrice.getCostPrice()),10);
JTextField sPriceTF = new JTextField(String.valueOf(testStockPrice.getSellingPrice()),10);