Results 1 to 3 of 3
Thread: JApplet problems
- 04-24-2008, 07:04 PM #1
Member
- Join Date
- Aug 2007
- Posts
- 20
- Rep Power
- 0
JApplet problems
so i have the following code
which returns these errors:Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; public class lab5 extends JApplet implements ActionListener { private lab5 invest = new lab5(); private JFrame loan = new JFrame("Loan Calculator"); private JButton btninvest = new JButton("Calculate your Investment"); private JButton btnloan = new JButton("Loan Calculator"); /*Initalize the applet*/ public void init() { getContentPane().setLayout(new FlowLayout()); getContentPane().add(btninvest); getContentPane().add(btnloan); btninvest.addActionListener(this); btnloan.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (e.getSource() == btninvest) { invest.setSize(300, 200); invest.setTitle("Investment Calculator"); invest.setVisible(true); } else if (e.getSource() == btnloan) { loan.setSize(300, 200); LoanApplet applet = new LoanApplet(); loan.getContentPane().add(applet); applet.init(); loan.setVisible(true); } } }
and here is the LoanApplet:H:\Advanced Java\Lab Work\Lab5\lab5.java:28: cannot find symbol
symbol : method setTitle(java.lang.String)
location: class lab5
invest.setTitle("Investment Calculator");
^
H:\Advanced Java\Lab Work\Lab5\lab5.java:34: cannot find symbol
symbol : class LoanApplet
location: class lab5
LoanApplet applet = new LoanApplet();
^
H:\Advanced Java\Lab Work\Lab5\lab5.java:34: cannot find symbol
symbol : class LoanApplet
location: class lab5
LoanApplet applet = new LoanApplet();
^
3 errors
Tool completed with exit code 1
i'm assuming it has something to do with my instantiation of the loanapplet but i'm not 100% sureJava Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.TitledBorder; public class LoanApplet extends JApplet implements ActionListener { // Declare and create text fields for interest rate // year, loan amount, monthly payment, and total payment private JTextField jtfAnnualInterestRate = new JTextField(); private JTextField jtfNumberOfYears = new JTextField(); private JTextField jtfLoanAmount = new JTextField(); private JTextField jtfMonthlyPayment = new JTextField(); private JTextField jtfTotalPayment = new JTextField(); // Declare and create a Compute Payment button private JButton jbtComputeLoan = new JButton("Compute Payment"); /** Initialize user interface */ public void init() { // Set properties on the text fields jtfMonthlyPayment.setEditable(false); jtfTotalPayment.setEditable(false); // Right align text fields jtfAnnualInterestRate.setHorizontalAlignment(JTextField.RIGHT); jtfNumberOfYears.setHorizontalAlignment(JTextField.RIGHT); jtfLoanAmount.setHorizontalAlignment(JTextField.RIGHT); jtfMonthlyPayment.setHorizontalAlignment(JTextField.RIGHT); jtfTotalPayment.setHorizontalAlignment(JTextField.RIGHT); // Panel p1 to hold labels and text fields JPanel p1 = new JPanel(new GridLayout(5, 2)); p1.add(new JLabel("Annual Interest Rate")); p1.add(jtfAnnualInterestRate); p1.add(new JLabel("Number of Years")); p1.add(jtfNumberOfYears); p1.add(new JLabel("Loan Amount")); p1.add(jtfLoanAmount); p1.add(new JLabel("Monthly Payment")); p1.add(jtfMonthlyPayment); p1.add(new JLabel("Total Payment")); p1.add(jtfTotalPayment); p1.setBorder(new TitledBorder("Enter interest rate, year and loan amount")); // Panel p2 to hold the button JPanel p2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); p2.add(jbtComputeLoan); // Add the components to the applet getContentPane().add(p1, BorderLayout.CENTER); getContentPane().add(p2, BorderLayout.SOUTH); // Register listener jbtComputeLoan.addActionListener(this); } /** Handle the Compute Payment button */ public void actionPerformed(ActionEvent e) { if (e.getSource() == jbtComputeLoan) { // Get values from text fields double interest = Double.parseDouble(jtfAnnualInterestRate.getText()); int year = Integer.parseInt(jtfNumberOfYears.getText()); double loanAmount = Double.parseDouble(jtfLoanAmount.getText()); // Create a loan object Loan loan = new Loan(interest, year, loanAmount); // Display monthly payment and total payment jtfMonthlyPayment.setText("" + (int)(loan.monthlyPayment() * 100) / 100.0); jtfTotalPayment.setText("" + (int)(loan.totalPayment() * 100) / 100.0); } } public static void main(String[] args) { // Create a frame JFrame frame = new JFrame("Applet is in the frame"); // Create an instance of the applet LoanApplet applet = new LoanApplet(); // Add the applet to the frame frame.getContentPane().add(applet, BorderLayout.CENTER); // Invoke applet's init method applet.init(); // Display the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 300); frame.setVisible(true); } }
- 04-24-2008, 07:10 PM #2
Why are you creating a new lab05 inside the lab05 class that doesn't make any sense.
- 04-24-2008, 07:36 PM #3
Member
- Join Date
- Aug 2007
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
Database to JApplet
By Preethi in forum New To JavaReplies: 0Last Post: 03-26-2008, 05:18 AM -
Another problem in JApplet :S
By juju in forum Java AppletsReplies: 2Last Post: 12-30-2007, 07:46 PM -
Problems while loading a JPanel to JApplet...
By Ananth Chellathurai in forum Java AppletsReplies: 0Last Post: 11-24-2007, 10:47 AM -
help with converting to JApplet
By Simmy in forum AWT / SwingReplies: 2Last Post: 08-09-2007, 08:45 AM -
JApplet and html
By paty in forum Java AppletsReplies: 1Last Post: 08-02-2007, 05:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks