Applet not working - Please Help!
Hi everybody,
I'm trying to make this calculator program work as an applet AND as an application. I tried using:
public class calcg extends JApplet implements ActionListener{ in many different ways, but it didn't work. Can sombody help me make it work?
Below is the source code for my calculator program.
Thanks in advance,
-Maria
ps-You can also e-mail me at [email protected]
// calculator
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class calcg extends JFrame implements ActionListener
private JButton one, two, three, four, five, six, seven,
eight, nine, zero, dec, eq, plus, minus, mult, div, clear;
private JLabel output, spacer;
private Container container;
private String operation;
private double num1, num2, answer;
private boolean clear_flag = false;
//set up GUI
public calcg()
//Create Title
super("Calculator");
JPanel container = new JPanel();
container.setLayout( new FlowLayout( FlowLayout.CENTER
output = new JLabel("");
output.setBorder(new MatteBorder(2,2,2,2,Color.gray));
output.setPreferredSize(new Dimension(1,26));
getContentPane().setBackground(Color.white);
getContentPane().add( "North",output );
getContentPane().add( "Center",container );
//set up spacer
spacer = new JLabel( "
container.add( spacer );
//set up clear
clear = new JButton( "CE" );
clear.addActionListener(this);
container.add( clear );
//set up seven and register its event handler
seven = new JButton( "7" );
seven.addActionListener(this);
container.add( seven );
//set up eight
eight = new JButton( "8" );
eight.addActionListener(this);
container.add( eight );
//set up nine
nine = new JButton( "9" );
nine.addActionListener(this);
container.add( nine );
//set up div
div = new JButton( "/" );
div.addActionListener(this);
container.add( div );
//set up four
four = new JButton( "4" );
four.addActionListener(this);
container.add( four );
//set up five
five = new JButton( "5" );
five.addActionListener(this);
container.add( five );
//set up six
six = new JButton( "6" );
six.addActionListener(this);
container.add( six );
//set up mult
mult = new JButton( "*" );
mult.addActionListener(this);
container.add( mult );
//set up one
one = new JButton( "1" );
one.addActionListener(this);
container.add( one );
//set up two
two = new JButton( "2" );
two.addActionListener(this);
container.add( two );
//set up three
three = new JButton( "3" );
three.addActionListener(this);
container.add( three );
//set up minus
minus = new JButton( "-" );
minus.addActionListener(this);
container.add( minus );
//set up zero
zero = new JButton( "0" );
zero.addActionListener(this);
container.add( zero );
//set up dec
dec = new JButton( "." );
dec.addActionListener(this);
container.add( dec );
//set up eq
eq = new JButton( "=" );
eq.addActionListener(this);
container.add( eq );
//set up plus
plus = new JButton( "+" );
plus.addActionListener(this);
container.add( plus );
//Set size and make visible
setSize( 190, 225 );
setVisible( true );
setResizable( false );
public void actionPerformed(ActionEvent ae)
JButton but = ( JButton )ae.getSource();
//Handle what button was pushed
//Action for dec button
if( but.getText() == "." )
//if dec is pressed, first check to make shure there
is not already a decimal
String temp = output.getText();
if( temp.indexOf( '.' ) == -1 )
output.setText( output.getText() + but.getText() );
//Action for clear button
else if( but.getText() == "CE" )
output.setText( "" );
operation = "";
num1 = 0.0;
num2 = 0.0;
//Action for plus button
else if( but.getText() == "+" )
operation = "+";
num1 = Double.parseDouble( output.getText() );
clear_flag = true;
//output.setText( "" );
//Action for minus button
else if( but.getText() == "-" )
operation = "-";
num1 = Double.parseDouble( output.getText() );
clear_flag = true;
//output.setText( "" );
//Action for mult button
else if( but.getText() == "*" )
operation = "*";
num1 = Double.parseDouble( output.getText() );
clear_flag = true;
//output.setText( "" );
//Action for div button
else if( but.getText() == "/" )
operation = "/";
num1 = Double.parseDouble( output.getText() );
clear_flag = true;
//output.setText( "" );
//Action for eq button
else if( but.getText() == "=" )
num2 = Double.parseDouble( output.getText() );
//handle addition
if( operation == "+" )
answer = num1 + num2;
else if( operation == "-" )
answer = num1 - num2;
else if( operation == "*" )
answer = num1 * num2;
else if( operation == "/" )
answer = num1 / num2;
//display answer in output field
output.setText( String.valueOf( answer ) );
clear_flag = true;
operation = "";
//Default action should only be used for numbers
else
if( clear_flag == true )
output.setText( "" );
clear_flag = false;
output.setText( output.getText() + but.getText() );
//execute application
public static void main( String args[] )
calcg application = new calcg();
application.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE );
}
Ok I think I know what you problem is.
First move the main method above the calcg method ok. Just to make it easy.
Then you did something like
public static void main( String args[] )
calcg application = new calcg();
>> application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); }}
the arrows indicate your error. You need to put the setDefaultCloseOperation inside the calcg method then you would put this:
public static void main(String[] args)
calcg application = new calcg();
application.calcg();
see you call the application to run the calcg method which will start your program.
Similar Messages
-
my iphone 4s does not start by power switch, it starts when i connect to pc. the proximity sensor is not working. please help.
Sounds like it may be a hardware issue.
Please contact Apple Support in your country.
Here is a list of numbers: http://support.apple.com/kb/HE57
Regards
J -
I have unabled 5 fingure gesture now not able to perform any task,also my power button is not working,please help me in removing this gesture,using I phone 4
I have unabled 5 fingure gesture now not able to perform any task,also my power button is not working,please help me in removing this gesture,using I phone 4
-
I have 4s iPhone , I download the iOS 7. Now the front receiver microphone is not working , please help me that how to fix the problem.
I live in South Africa, and I had the same problem with my iPhone 4.
After weeks of frustration and swearing, I was in the process of restoring my phone to a previous iOS. To do that you need to turn the "Find my iPhone" option off, since i turned it off, my problem was solved. No need to repair anything or revert back to old iOS.
***** that i cant use Find my iPhone, but atleast i can use my phone. -
I installed windows 7 on my macbook pro. all is working but lan adaptor and sound od laptop is not working. please help me or send the link where i can download the these drivers.I have lost my resource cd .
If you are running Lion or Mountain Lion, the drivers are downloaded from within Bootcamp Assistant. If you are running Snow Leopard the drivers are on your Snow Leopard install disk.
Read the Bootcamp Install Guide for your version of OSx. http://www.apple.com/support/bootcamp/
Bootcamp questions should be asked in the Bootcamp forum where the Bootcamp gurus hang out https://discussions.apple.com/community/windows_software/boot_camp -
this is what my iphone 4 shows. iv tried switching off again and again, closing apps by double tapping the home button but still not working. please help.
is there any other method to download ios 6.1.2.
my phone is not being recognized by itunes on my new windows 8. neither its working on touch copy.
kindly help.
thankswell in thatcase, i need another help .
thanks for your instant reply.
i have currently bought a new laptop (windows 8) and my iphone is not being recognized by itunes.
because i have no backup on my previous laptop, i downloaded touchcopy but even touch copy is not recognizing my iphone. -
while updating 4.0 version to 5 version system shows sim card is not valid. My iphone is not working .Please help me
I would imagine your iPhone was hacked to make it work on your local carrier.
Updating the iOs to 5.xx will lock it back to the original carrier .The carrier holding the lock are the only
entity able to authorise the unlock .You will have to contact them and see if they unlock and the terms the apply -
HT1414 my handsfree is not working please help me
Hi There!
I am using Iphone 4s and ny handsfree in not working please help meTry restarting you iPhone by holding down the on/off and the home buttons at the same time until you see the Apple logo.
-
I have ne iphone 5, i been setting my email using AT&T global but it is not working, please help me on the correct configuration
Contact the email provider and obtain the correct setup information.
-
The built-in mic in g50 122ca laptop model is not working. please help me out.
the built-in mic in g50 122ca laptop model is not working. please help me out. OS: Windows Vista (32-bit)
here is a sample code .
so far you procedure looks good but
i bet you have to specify the name of report , instead of 'filename'.
see this
Plist_id := GET_PARAMETER_LIST('P_name');
IF NOT ID_NULL(Plist_id) THEN
DESTROY_PARAMETER_LIST(Plist_id);
END IF;
Plist_id := CREATE_PARAMETER_LIST('P_name');
ADD_PARAMETER( Plist_id, 'P_Receive_date', TEXT_PARAMETER, TO_CHAR(Receive_date,'mm/dd/yyyy'));
ADD_PARAMETER( Plist_id, 'P_Hearing_date', TEXT_PARAMETER, TO_CHAR(Hearing_date,'mm/dd/yyyy'));
ADD_PARAMETER( Plist_id, 'P_Hearing_time', TEXT_PARAMETER, TO_CHAR(Hearing_time,'mm/dd/yyyy'));
ADD_PARAMETER( Plist_id, 'P_Issue_date', TEXT_PARAMETER, TO_CHAR(Issue_date,'mm/dd/yyyy'));
ADD_PARAMETER( Plist_id, 'P_Workshop_date', TEXT_PARAMETER, TO_CHAR(Workshop_date,'mm/dd/yyyy'));
-- RUN_PRODCT(REPORTS,'..\Reports\Pro_License',SYNCHRONOUS, RUNTIME, FILESYSTEM, Plist_id, NULL);
-- here Pro_License is the name of report.
did you tried to see if the parameter passed using a message ?
try
message('parameter name'); pause; write this before "run_report". -
my itnues for pc is not working it shows that iTunes has stop working,I have downloaded Itnues many times but still it is not working, please help me
Please helppppp
-
All my old tv shows are not working please help my computer sed I have to Atheris 5 computers to play all my old tv shows I Pade for with eney Itunas cards.
What do y mean by not work?
What happens when y try to play them on yur iPod?
What happens when yo try to play them in iTunes on yur computer?
If you get a message what is the exact wording of the message?
You can redownload most iTunes purchases by:
Downloading past purchases from the App Store, iBookstore, and iTunes Store
Some countries do not allow redownloads some kinds of media -
The click at touchpad is not working, please help!!!
I use Macpro, recently the click at touchpad is not working, please help!!! Thank you !!
For this issue AppleCare support told me to so a SMC reset as follows:
Power the machine OFF.
At the SAME TIME hold down the following buttons:
Shift
Control
Option
Power
Then release all buttons. Power up the Macbook and see if the trackpad button work.
Hope this helps.
Bill -
hi
i tried to update to ios 8.2 on my iphone 5s when message popup to me now my iphone not working, please help i dont want to lose my dataWhat is the exact text of the message you got? And did you not back up before you updated?
-
After I updated my new Ipad with IOS 6, now Map& Dictation icon are not working. please help me
Thank you wjsten for your soon reply. Unfortunately on these days I'm in a country that Apple don't have any retail store here and for sake of time I prefer to fix it myself to DHL it to the nearest country to use its warranty. Do you have any idea how can I fix it? Do you think it's a software issue?
Maybe you are looking for
-
Do I need a separate volume.
My question, do you need a separate volume for Time Machine. or can data reside on the same volume as the backup.
-
I tried to download the full installer of webcenter 11.1.1.5.0 from http://www.oracle.com/technetwork/middleware/webcenter/downloads/index.html It says directly below the link that this is a full installer but when you download it, the readme says it
-
Creating a hyperlink from a picture in a pdf that opens Outlook email
I use Adobe Acrobat 8.1 and am trying to create a link in a PDF so that with READER 7.0 or higher, when a recipient clicks on a picture (object) it will access Outlook and open up a new email that the recipient would complete and then send! Is it via
-
Not sure if this question is related to the massive Multicast thread earlier (much of which is all g(r)eek to me, I'm afraid) but I'm surprised that I still can't receive the channels 225 and upwards. I still get a message saying that I do not have a
-
hello *okay this following is WORKING and CORRECT:* CREATE OR REPLACE FUNCTION fnGetParents ObjectId number, ObjectClassifier varchar2 RETURN typescursorType IS fnGetParents_cursor types.cursorType; BEGIN EXECUTE IMMEDIATE (''CREATE GLOBAL TEMPORARY