Re: Add parentheses to a claculator.
From: Virgil Green (vjg_at_obsydian.com)
Date: 12/11/03
- Next message: John C. Bollinger: "Re: Stateless session bean that multi threads?"
- Previous message: Andrew Thompson: "Re: Storing/retrieving BLOBs with JSPs"
- In reply to: Backo: "Add parentheses to a claculator."
- Next in thread: farview_at_earthlink.net: "Re: Add parentheses to a claculator."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 11 Dec 2003 18:43:35 GMT
"Backo" <red_hak@hotmail.com> wrote in message
news:a5581fbb.0312111003.468e340b@posting.google.com...
> Please help me to add 4 level parantheses to the following calculator:
> import java.awt.*;
> import java.awt.event.*;
> import java.applet.*;
> public class CalculateurNC extends Applet {
> String arg="";
String parens="(((())))";
> int rezVal=0;
> Button number[] = new Button[10];
> Button func[] = new Button[6];
> Panel num_panel;
> Panel func_panel;
> Panel rez_panel;
> TextField rez;
> char oper;
> public void init(){
> oper = ' ';
> setLayout(null);
> num_panel = new Panel();
> num_panel.setLayout(new GridLayout(4,3));
> for(int i=9; i>=0; i--){
> number[i] = new Button((new String()).valueOf(i));
> number[i].addActionListener(new BN());
> num_panel.add(number[i])
> }
> func[0] = new Button("C");
> func[0].addActionListener(new C());
> num_panel.add(func[0]);
> func[1] = new Button("=");
> func[1].addActionListener(new OPER());
> num_panel.add(func[1]);
> num_panel.setBounds(20,100,180,180);
> add(num_panel);
> func_panel = new Panel();
> func_panel.setLayout(new GridLayout(4,1));
> func[2] = new Button("+");
> func[2].addActionListener(new OPER());
> func_panel.add(func[2]);
> func[3] = new Button("-");
> func[3].addActionListener(new OPER());
> func_panel.add(func[3]);
> func[4] = new Button("*");
> func[4].addActionListener(new OPER());
> func_panel.add(func[4]);
> func[5] = new Button("^");
> func[5].addActionListener(new OPER());
> func_panel.add(func[5]);
> func_panel.setBounds(210,100,65,180);
> add(func_panel);
> rez_panel = new Panel();
> rez = new TextField("0",10);
> rez_panel.add(rez);
> rez_panel.setBounds(20,20,240,40);
> add(rez_panel);
> }
>
> class BN implements ActionListener{
> public void actionPerformed(ActionEvent e) {
> arg += e.getActionCommand();
> rez.setText(arg);
> }
> }
>
> class OPER implements ActionListener{
> public void actionPerformed(ActionEvent e) {
> int i,help,argi;
> if(arg.length()==0)argi=0;
> else argi = (new Integer(arg)).intValue();
> switch(oper){
> case '+': rezVal += argi;break;
> case '-': rezVal -= argi;break;
> case '*': rezVal *= argi;break;
> case '=': oper = ' ';break;
> case '^':
> for(i=1,help=rezVal; i < argi;i++)
> rezVal *=help;
> break;
> case ' ': rezVal= argi;
> }
> rez.setText(rezVal+"");
> arg = "";
> oper = e.getActionCommand().charAt(0);
> }
> }
>
> class C implements ActionListener{
> public void actionPerformed(ActionEvent e) {
> arg = "";
> rezVal =0;
> oper = ' ';
> rez.setText(rezVal+"");
> }
> }
Sorry, I couldn't resist.
- Virgil
- Next message: John C. Bollinger: "Re: Stateless session bean that multi threads?"
- Previous message: Andrew Thompson: "Re: Storing/retrieving BLOBs with JSPs"
- In reply to: Backo: "Add parentheses to a claculator."
- Next in thread: farview_at_earthlink.net: "Re: Add parentheses to a claculator."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]