Hi! I needed help making a java applet for a calculator. In myprevious post, som
ID: 3618801 • Letter: H
Question
Hi! I needed help making a java applet for a calculator. In myprevious post, someone helped me make a code but how do I transferthis code into applet function?Also, is there a website or do you know of different things I cando to personalize the way my calculator/applet will look like?Thank you!
Explanation / Answer
x.Hlor="red">please rate - thanks real basic calculator-as mentioned in my message import java.awt.*; import java.applet.*; import java.awt.event.*; public class calc extends Applet implements ActionListener { private int first,second,answer,operation; TextField numberfield = new TextField(10); Button plusbutton = new Button("+"); Button minusbutton = new Button("-"); Button multbutton = new Button("*"); Button divbutton = new Button("/"); Button equalbutton = new Button("="); Button clrbutton = new Button("clr"); private int mathh() { switch ( operation){ case 1: answer=first+second; break; case 2: answer=first-second; break; case 3: answer=first*second; break; case 4: answer=first/second; break;} return answer; } public void init() { add(numberfield); add(plusbutton); add(minusbutton); add(multbutton); add(divbutton); add(equalbutton); add(clrbutton); numberfield.addActionListener(this); plusbutton.addActionListener(this); minusbutton.addActionListener(this); multbutton.addActionListener(this); divbutton.addActionListener(this); equalbutton.addActionListener(this); clrbutton.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==plusbutton) {operation=1; first=Integer.parseInt(numberfield.getText()); numberfield.setText("");} if(e.getSource()==minusbutton) {operation=2; first=Integer.parseInt(numberfield.getText()); numberfield.setText("");} if(e.getSource()==multbutton) {operation=3; first=Integer.parseInt(numberfield.getText()); numberfield.setText("");} if(e.getSource()==divbutton) { operation=4; first=Integer.parseInt(numberfield.getText()); numberfield.setText("");} if(e.getSource()==equalbutton) { second=Integer.parseInt(numberfield.getText()); answer=mathh(); numberfield.setText(answer +"");} if(e.getSource()==clrbutton) { numberfield.setText(""); first=-100; &n
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.