|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
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 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:")); } } |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > Java problem - Cant resolve symbol(JTextFields)?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|