Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-24-2008, 09:04 PM
Member
 
Join Date: Aug 2007
Posts: 20
Rgfirefly24 is on a distinguished road
JApplet problems
so i have the following code
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); } } }
which returns these errors:
Quote:
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
and here is the LoanApplet:

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); } }
i'm assuming it has something to do with my instantiation of the loanapplet but i'm not 100% sure
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-24-2008, 09:10 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
Why are you creating a new lab05 inside the lab05 class that doesn't make any sense.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-24-2008, 09:36 PM
Member
 
Join Date: Aug 2007
Posts: 20
Rgfirefly24 is on a distinguished road
Ok so your right lol, i have no idea about applets or anything of the sort. I changed it to read

private JFrame invest = new JFrame();

it loads now

Last edited by Rgfirefly24 : 04-24-2008 at 09:41 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database to JApplet Preethi New To Java 0 03-26-2008 07:18 AM
Another problem in JApplet :S juju Java Applets 2 12-30-2007 09:46 PM
Problems while loading a JPanel to JApplet... Ananth Chellathurai Java Applets 0 11-24-2007 12:47 PM
help with converting to JApplet Simmy AWT / Swing 2 08-09-2007 10:45 AM
JApplet and html paty Java Applets 1 08-02-2007 07:41 PM


All times are GMT +3. The time now is 11:01 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org