473,729 Members | 2,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating multiple windows from an applet

8 New Member
I'm suppose to write an applet that contains two buttons Investment calculator and Loan Calculator. When the Investment Calculator button is clicked, a frame appears in a new window for calculating future investment values. When you click Loan Calculator button, a frame appears in a separate new window for computong loan payments.

Here's my coding:

// Lab3.java:
import java.awt.*;
import java.awt.event. *;
import javax.swing.*;

public class Lab3 extends JApplet implements ActionListener {
private Investment investmentFrame = new Investment();
private JFrame loanFrame = new JFrame("Loan Calculator");
private JButton jbtInvestment = new JButton("Invest ment Calculator");
private JButton jbtLoan = new JButton("Loan Calculator");

public void init() {
getContentPane( ).setLayout(new FlowLayout());
getContentPane( ).add(jbtInvest ment);
getContentPane( ).add(jbtLoan);
jbtInvestment.a ddActionListene r(this);
jbtLoan.addActi onListener(this );
}

public void actionPerformed (ActionEvent e) {
if (e.getSource() == jbtInvestment) {
investmentFrame .setSize(300, 200);
investmentFrame .setTitle("Inve stment Calculator");
investmentFrame .setVisible(tru e);
}
else if (e.getSource() == jbtLoan) {
loanFrame.setSi ze(300, 200);
LoanApplet applet = new LoanApplet();
loanFrame.getCo ntentPane().add (applet);
applet.init();
loanFrame.setVi sible(true);
}
}
public static void main(String[] args) {
//Create a frame
JFrame frame = new JFrame("Lab3");

//Create an instance of the applet
Lab3 applet = new Lab3();

//Add the applet to the frame
frame.add(apple t, BorderLayout.CE NTER);

//Invoke init and start
applet.init();
applet.start();

//Display the frame
frame.setLocati onRelativeTo(nu ll);
frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);
frame.setSize(3 00, 300);
frame.setVisibl e(true);
}
}



Here's the coding for the LoanApplet:

import java.awt.*;
import java.awt.event. *;
import javax.swing.*;
import javax.swing.bor der.TitledBorde r;

public class LoanApplet extends JApplet {
// Declare and create text fields for interest rate
// year, loan amount, monthly payment, and total payment
private JTextField jtfAnnualIntere stRate = new JTextField();
private JTextField jtfNumberOfYear s = new JTextField();
private JTextField jtfLoanAmount = new JTextField();
private JTextField jtfMonthlyPayme nt = new JTextField();
private JTextField jtfTotalPayment = new JTextField();

// Declare and create a Compute Payment button
private JButton jbtComputeLoan = new JButton("Comput e Payment");

/** Initialize user interface */
public void init() {
// Set properties on the text fields
jtfMonthlyPayme nt.setEditable( false);
jtfTotalPayment .setEditable(fa lse);

// Right align text fields
jtfAnnualIntere stRate.setHoriz ontalAlignment( JTextField.RIGH T);
jtfNumberOfYear s.setHorizontal Alignment(JText Field.RIGHT);
jtfLoanAmount.s etHorizontalAli gnment(JTextFie ld.RIGHT);
jtfMonthlyPayme nt.setHorizonta lAlignment(JTex tField.RIGHT);
jtfTotalPayment .setHorizontalA lignment(JTextF ield.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(jtfAnnua lInterestRate);
p1.add(new JLabel("Number of Years"));
p1.add(jtfNumbe rOfYears);
p1.add(new JLabel("Loan Amount"));
p1.add(jtfLoanA mount);
p1.add(new JLabel("Monthly Payment"));
p1.add(jtfMonth lyPayment);
p1.add(new JLabel("Total Payment"));
p1.add(jtfTotal Payment);
p1.setBorder(ne w
TitledBorder("E nter interest rate, year and loan amount"));

// Panel p2 to hold the button
JPanel p2 = new JPanel(new FlowLayout(Flow Layout.RIGHT));
p2.add(jbtCompu teLoan);

// Add the components to the applet
add(p1, BorderLayout.CE NTER);
add(p2, BorderLayout.SO UTH);

// Register listener
jbtComputeLoan. addActionListen er(new ButtonListener( ));
}

/** Handle the Compute Payment button */
private class ButtonListener implements ActionListener {
public void actionPerformed (ActionEvent e) {
// Get values from text fields
double interest =
Double.parseDou ble(jtfAnnualIn terestRate.getT ext());
int year =
Integer.parseIn t(jtfNumberOfYe ars.getText());
double loanAmount =
Double.parseDou ble(jtfLoanAmou nt.getText());

// Create a loan object
Loan loan = new Loan(interest, year, loanAmount);

// Display monthly payment and total payment
jtfMonthlyPayme nt.setText(Stri ng.format("%.2f ",
loan.getMonthly Payment()));
jtfTotalPayment .setText(String .format("%.2f",
loan.getTotalPa yment()));
}
}

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.add(apple t, BorderLayout.CE NTER);

// Invoke applet's init method
applet.init();

// Display the frame
frame.setLocati onRelativeTo(nu ll); // Center the frame
frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);
frame.setSize(3 00, 300);
frame.setVisibl e(true);
}
}



Here's my command results I don't see what I'm doing wrong please help:

K:\Lab3.java:28 : cannot find symbol
symbol : class LoanApplet
location: class Lab3
LoanApplet applet = new LoanApplet();
^
K:\Lab3.java:28 : cannot find symbol
symbol : class LoanApplet
location: class Lab3
LoanApplet applet = new LoanApplet();
^
2 errors

Tool completed with exit code 1
Oct 26 '07 #1
4 7820
r035198x
13,262 MVP
I'm suppose to write an applet that contains two buttons Investment calculator and Loan Calculator. When the Investment Calculator button is clicked, a frame appears in a new window for calculating future investment values. When you click Loan Calculator button, a frame appears in a separate new window for computong loan payments.

Here's my coding:

// Lab3.java:
import java.awt.*;
import java.awt.event. *;
import javax.swing.*;

public class Lab3 extends JApplet implements ActionListener {
private Investment investmentFrame = new Investment();
private JFrame loanFrame = new JFrame("Loan Calculator");
private JButton jbtInvestment = new JButton("Invest ment Calculator");
private JButton jbtLoan = new JButton("Loan Calculator");

public void init() {
getContentPane( ).setLayout(new FlowLayout());
getContentPane( ).add(jbtInvest ment);
getContentPane( ).add(jbtLoan);
jbtInvestment.a ddActionListene r(this);
jbtLoan.addActi onListener(this );
}

public void actionPerformed (ActionEvent e) {
if (e.getSource() == jbtInvestment) {
investmentFrame .setSize(300, 200);
investmentFrame .setTitle("Inve stment Calculator");
investmentFrame .setVisible(tru e);
}
else if (e.getSource() == jbtLoan) {
loanFrame.setSi ze(300, 200);
LoanApplet applet = new LoanApplet();
loanFrame.getCo ntentPane().add (applet);
applet.init();
loanFrame.setVi sible(true);
}
}
public static void main(String[] args) {
//Create a frame
JFrame frame = new JFrame("Lab3");

//Create an instance of the applet
Lab3 applet = new Lab3();

//Add the applet to the frame
frame.add(apple t, BorderLayout.CE NTER);

//Invoke init and start
applet.init();
applet.start();

//Display the frame
frame.setLocati onRelativeTo(nu ll);
frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);
frame.setSize(3 00, 300);
frame.setVisibl e(true);
}
}



Here's the coding for the LoanApplet:

import java.awt.*;
import java.awt.event. *;
import javax.swing.*;
import javax.swing.bor der.TitledBorde r;

public class LoanApplet extends JApplet {
// Declare and create text fields for interest rate
// year, loan amount, monthly payment, and total payment
private JTextField jtfAnnualIntere stRate = new JTextField();
private JTextField jtfNumberOfYear s = new JTextField();
private JTextField jtfLoanAmount = new JTextField();
private JTextField jtfMonthlyPayme nt = new JTextField();
private JTextField jtfTotalPayment = new JTextField();

// Declare and create a Compute Payment button
private JButton jbtComputeLoan = new JButton("Comput e Payment");

/** Initialize user interface */
public void init() {
// Set properties on the text fields
jtfMonthlyPayme nt.setEditable( false);
jtfTotalPayment .setEditable(fa lse);

// Right align text fields
jtfAnnualIntere stRate.setHoriz ontalAlignment( JTextField.RIGH T);
jtfNumberOfYear s.setHorizontal Alignment(JText Field.RIGHT);
jtfLoanAmount.s etHorizontalAli gnment(JTextFie ld.RIGHT);
jtfMonthlyPayme nt.setHorizonta lAlignment(JTex tField.RIGHT);
jtfTotalPayment .setHorizontalA lignment(JTextF ield.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(jtfAnnua lInterestRate);
p1.add(new JLabel("Number of Years"));
p1.add(jtfNumbe rOfYears);
p1.add(new JLabel("Loan Amount"));
p1.add(jtfLoanA mount);
p1.add(new JLabel("Monthly Payment"));
p1.add(jtfMonth lyPayment);
p1.add(new JLabel("Total Payment"));
p1.add(jtfTotal Payment);
p1.setBorder(ne w
TitledBorder("E nter interest rate, year and loan amount"));

// Panel p2 to hold the button
JPanel p2 = new JPanel(new FlowLayout(Flow Layout.RIGHT));
p2.add(jbtCompu teLoan);

// Add the components to the applet
add(p1, BorderLayout.CE NTER);
add(p2, BorderLayout.SO UTH);

// Register listener
jbtComputeLoan. addActionListen er(new ButtonListener( ));
}

/** Handle the Compute Payment button */
private class ButtonListener implements ActionListener {
public void actionPerformed (ActionEvent e) {
// Get values from text fields
double interest =
Double.parseDou ble(jtfAnnualIn terestRate.getT ext());
int year =
Integer.parseIn t(jtfNumberOfYe ars.getText());
double loanAmount =
Double.parseDou ble(jtfLoanAmou nt.getText());

// Create a loan object
Loan loan = new Loan(interest, year, loanAmount);

// Display monthly payment and total payment
jtfMonthlyPayme nt.setText(Stri ng.format("%.2f ",
loan.getMonthly Payment()));
jtfTotalPayment .setText(String .format("%.2f",
loan.getTotalPa yment()));
}
}

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.add(apple t, BorderLayout.CE NTER);

// Invoke applet's init method
applet.init();

// Display the frame
frame.setLocati onRelativeTo(nu ll); // Center the frame
frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);
frame.setSize(3 00, 300);
frame.setVisibl e(true);
}
}



Here's my command results I don't see what I'm doing wrong please help:

K:\Lab3.java:28 : cannot find symbol
symbol : class LoanApplet
location: class Lab3
LoanApplet applet = new LoanApplet();
^
K:\Lab3.java:28 : cannot find symbol
symbol : class LoanApplet
location: class Lab3
LoanApplet applet = new LoanApplet();
^
2 errors

Tool completed with exit code 1
Please use code tags when posting code.
Did you compile the LoanApplet class successfully first?
Oct 26 '07 #2
tudyfruity18
8 New Member
Please use code tags when posting code.
Did you compile the LoanApplet class successfully first?
Yes the LoanApplet compiled and ran successfully
Oct 26 '07 #3
tudyfruity18
8 New Member
Please use code tags when posting code.
Did you compile the LoanApplet class successfully first?
Yes it complied and ran successfully
Oct 26 '07 #4
r035198x
13,262 MVP
Yes it complied and ran successfully
Are these classes in the same folder?
Oct 27 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
5017
by: 3A Web Hosting | last post by:
Hi Is it possible to perform multiple file uploads via a form? It's no problem uploading single files but I want to be able to highlight a group of files and upload them all in one go. My current method, multiple <INPUT TYPE="FILE" NAME="userfile"> entries, works but means selecting each file individually. -- Colin
16
7515
by: noah | last post by:
Does PHP have a feature to associate Cookie sessions with a persistent database connection that will allow a single transaction across multiple HTTP requests? Here is how I imagine my process: I have an series of interactive HTML forms. The user begins a Cookie session. A database connection is opened and a transaction is begun. After the user goes through any number of pages where they update the database they finish on a page where...
2
2406
by: noplasma | last post by:
Does Mozilla 1.4 support multiple JRE plugins? I need to support both the 1.3.1 and 1.4.1 version levels (to be called separately using EMBED flags). If so, how do I configure that? Also related, does Netscape 7 / Mozilla 1.0.1 support JRE 1.3.1? When I link to the sparc/ns600/libjavaplugin_oji.so file, my applet fails to load, while it works with the JRE 1.4.1 file. Kind Regards, Daniel
6
10567
by: x. zhang | last post by:
Hi Guys, We know that we can use <input type=file ...> to upload one file per time to the server. My question is if there are some way to upload multiple files per time to the server. (Of course, we can use <input type=file ...> multiple times and then submit once. But this is not what I want, because we have to click "browse" button several times to select multiple files before submit in this way.) "Upload multiple files PER TIME", I...
0
1508
by: Michael Klose | last post by:
Hi, not sure if this is the right group, if not, please post a followup to the right group. Basically, what I would like to do is to produce a documentation cdrom, but which has a full text search cabability. I looked for hours, butr the best thing I have come up with is the windows .chm mechanism. This allows me to do a full text search.
6
18717
by: Andi Reisenhofer | last post by:
Hallo C# folks, Somebody know how to create a ODBC DSN dynamically in c# program. Also interesting for me would be the connectionstring for an Access Database. Thinks a lot Andreas
4
2053
by: nickjunkinbox | last post by:
I am trying to decide how to read text files from the client, do some reformatting, and then write back to the client (without uploading to the server). These files could be fairly big in html/aspx terms (hundreds of Mb), so I need an efficient method. I understand the security implications of using web apps for this (technically it should be written as a windows app) but I wanted to see if anyone had any thoughts/approaches to this...
12
3162
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without restarting the application. What I did was to create an AppDomain that loaded the plugins and everything was great, until I tried to pass something else that strings between the domains...
0
1237
by: suraneng | last post by:
I develop web-based application that use java applet to connect scanner by Twain, when applet popup windows for select Twain source (call Twain from java applet) then it scan a picture correctly, but I try switch Windows language from English to Thai (or Thai to English) to input something. My applet windows was not response. My Applet was signed correctly. I use - Windows XP and Internet Explorer 6 Sp2 - Java 1.4.2 for development -...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.