Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package valutaEspressione;
- import java.awt.BorderLayout;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- public class Calcolatrice { //DA COMPLETARE
- private static class FrontEnd extends JFrame implements ActionListener{
- private static final long serialVersionUID = 1L;
- JPanel q,p0,k,p1,p2,j = new JPanel();
- JTextField jtf;
- JButton zero,uno,due,tre,quattro,cinque,sei,sette,otto,nove,buh,history,
- diviso,per,piu,meno,pow,uguale,mod,punto,pa,pc,back,del = new JButton("0");
- public FrontEnd(){
- setTitle("Calcolatrice");
- setSize(500,250);
- setLocation(500,200);
- //...
- JPanel q=new JPanel();
- JTextField jtf=new JTextField("",35);
- jtf.addActionListener(this);
- q.add(jtf);
- JPanel p0=new JPanel();
- p0.setLayout( new GridLayout(2,1,5,5));
- p0.add(q,BorderLayout.NORTH);
- JPanel k=new JPanel();
- k.setLayout( new GridLayout(1,2,5,5));
- //...
- JPanel p1=new JPanel();
- p1.setLayout( new GridLayout(3,6,5,5) );
- JPanel p2=new JPanel();
- p2.setLayout( new GridLayout(1,2,5,5));
- JPanel j=new JPanel();
- j.setLayout(new GridLayout(1,3,5,5));
- //JButton buh= new JButton("?");
- //buh.addActionListener(this);
- //JButton history= new JButton("HISTORY");
- //history.addActionListener(this);
- //JButton sette=new JButton("7");
- //sette.addActionListener(this);
- //JButton otto=new JButton("8");
- //otto.addActionListener(this);
- //JButton nove=new JButton("9");
- //nove.addActionListener(this);
- //JButton diviso=new JButton("/");
- //diviso.addActionListener(this);
- //JButton quattro=new JButton("4");
- //quattro.addActionListener(this);
- //JButton cinque=new JButton("5");
- //cinque.addActionListener(this);
- //JButton sei=new JButton("6");
- //sei.addActionListener(this);
- //JButton per=new JButton("X");
- //per.addActionListener(this);
- //JButton uno=new JButton("1");
- //uno.addActionListener(this);
- //JButton due=new JButton("2");
- //due.addActionListener(this);
- //JButton tre=new JButton("3");
- //tre.addActionListener(this);
- //JButton meno=new JButton("-");
- //meno.addActionListener(this);
- //JButton zero=new JButton("0");
- //zero.addActionListener(this);
- //JButton punto=new JButton(",");
- //punto.addActionListener(this);
- //JButton uguale=new JButton("=");
- //uguale.addActionListener(this);
- //JButton piu=new JButton("+");
- //piu.addActionListener(this);
- //JButton back=new JButton("BACK");
- //back.addActionListener(this);
- //JButton del= new JButton("CLEAR");
- //del.addActionListener(this);
- //JButton pa= new JButton("(");
- //pa.addActionListener(this);
- //JButton pc=new JButton(")");
- //pc.addActionListener(this);
- //JButton mod=new JButton("%");
- //mod.addActionListener(this);
- //JButton pow=new JButton("EXP");
- //pow.addActionListener(this);
- //...
- j.add(zero); j.add(punto); j.add(mod);
- k.add(history); k.add(buh);
- p1.add(sette); p1.add(otto); p1.add(nove); p1.add(diviso); p1.add(back); p1.add(del);
- p1.add(quattro); p1.add(cinque); p1.add(sei); p1.add(per); p1.add(pa); p1.add(pc);
- p1.add(uno); p1.add(due); p1.add(tre); p1.add(meno); p1.add(piu); p1.add(pow);
- //...
- p0.add(k,BorderLayout.SOUTH);
- p2.add(j,BorderLayout.WEST);
- p2.add(uguale,BorderLayout.EAST);
- add( p0, BorderLayout.NORTH ); //aggiunta del pannello p alla JFrame
- add( p1, BorderLayout.CENTER);
- add( p2, BorderLayout.SOUTH);
- zero.addActionListener(this);
- }//costruttore
- public void actionPerformed(ActionEvent evt){
- if(evt.getSource()==zero) jtf.setText(jtf.getText()+"0");
- else if(evt.getSource()==uno) jtf.setText(jtf.getText()+"1");
- else if(evt.getSource()==due) jtf.setText(jtf.getText()+"2");
- else if(evt.getSource()==tre) jtf.setText(jtf.getText()+"3");
- }
- }//FrontEnd
- public static void main( String[] args ){
- FrontEnd fe=new FrontEnd();
- fe.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement