How can I personalize the way my calculator will look like on theapplet screen?
ID: 3618811 • Letter: H
Question
How can I personalize the way my calculator will look like on theapplet screen? Can I add colors, change font, etc.?Explanation / Answer
x.Hlor="red">please rate - thanks some ideas 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() {setBackground(Color.yellow); numberfield.setBackground(Color.green); add(numberfield); Font b = new Font("SansSerif", Font.BOLD, 10); plusbutton.setFont(b); add(plusbutton); Font c = new Font("SansSerif", Font.BOLD, 25); minusbutton.setFont(c); 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) { &
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.