ΑΝΑΚΟΙΝΩΣΗ Οι εγγραφές στα εργαστήρια του μαθήματος Διαδικτυακός Προγραμματισμός θα γίνουν την Τρίτη 8/11/2011 και ώρα 12.00 στην αίθουσα 205. Ο διδάσκων Δρ Πετρανωνάκης Παύλος //=========================================== import javax.swing.*; import java.awt.*; import javax.swing.event.*; import java.awt.event.*; public class grafika1 extends JFrame { /** * Creates a new instance of grafika1. */ /** * @param args the command line arguments */ public static void main(String[ ] args) { grafika1 form =new grafika1(); form.setBounds(200,150,350,400); form.setTitle("LESSON 1 JAVA"); form.setDefaultCloseOperation(EXIT_ON_CLOSE); form.show(); // TODO code application logic here } //=========================================== /** * @(#)grafika2.java * * * @author * @version 1.00 2011/10/26 */ import javax.swing.*; import java.awt.*; import javax.swing.event.*; import java.awt.event.*; public class grafika2 extends JFrame implements ActionListener { // TODO code application logic here JPanel obj=new JPanel(); GridLayout grid= new GridLayout(5,3); JLabel lbl1=new JLabel("Number 1"); JTextField text1=new JTextField(10); JLabel lbl02 = new JLabel(" "); JLabel lbl2 = new JLabel("Number 2"); JTextField text2=new JTextField(10); JLabel lbl03 = new JLabel(" "); JLabel lbl01 = new JLabel(" "); JButton b1= new JButton("add"); JLabel lbl04 = new JLabel(" "); JLabel lbl4 = new JLabel("Result"); JTextField text3=new JTextField(10); JLabel lbl05 = new JLabel(" "); public grafika2() { obj.setLayout(grid); obj.add(lbl1); obj.add(text1); obj.add(lbl02); obj.add(lbl2); obj.add(text2); obj.add(lbl03); obj.add(lbl01); b1.addActionListener(this); obj.add(b1); obj.add(lbl04); obj.add(lbl4); obj.add(text3); obj.add(lbl05); setContentPane(obj);} public void actionPerformed(ActionEvent e) { if(e.getSource()==b1) { int sum=Integer.parseInt(text1.getText())+Integer.parseInt(text2.getText()); text3.setText(String.valueOf(sum)); } } public static void main(String[] args) { grafika2 form= new grafika2(); form.setBounds(200,150,350,400); form.setTitle("LESSON 2"); form.setDefaultCloseOperation(EXIT_ON_CLOSE); form.show(); } } //==================================================================== /** * @(#)grafika3.java * * * @author * @version 1.00 2011/10/27 */ import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.*; public class grafika3 extends JFrame implements ActionListener { JButton north,west,east,south,center; JTextField text1,text2; public grafika3() { JPanel bpanel=new JPanel(); JPanel inpanel =new JPanel(); center= new JButton("center+"); west= new JButton("west-"); east= new JButton("east*"); south= new JButton("south/"); north= new JButton("north%"); text1=new JTextField(10); text2=new JTextField(10); bpanel.setLayout(new BorderLayout()); inpanel.setLayout(new FlowLayout()); bpanel.add(north,"North"); bpanel.add(south,"South"); bpanel.add(east,"East"); bpanel.add(west,"West"); bpanel.add(inpanel,"Center"); inpanel.add(text1); inpanel.add(text2); inpanel.add(center); center.addActionListener(this); south.addActionListener(this); east.addActionListener(this); west.addActionListener(this); north.addActionListener(this); setContentPane(bpanel); } public void actionPerformed(ActionEvent evt) { String sum=""; int sum1; if(evt.getSource()==center) { sum1=Integer.parseInt(text1.getText())+Integer.parseInt(text2.getText()); sum=String.valueOf(sum1); JOptionPane.showMessageDialog(null,sum,"RESULT",JOptionPane.INFORMATION_MESSAGE); } if(evt.getSource()==north) { sum1=Integer.parseInt(text1.getText())%Integer.parseInt(text2.getText()); sum=String.valueOf(sum1); JOptionPane.showMessageDialog(null,sum,"RESULT",JOptionPane.INFORMATION_MESSAGE); } if(evt.getSource()==east) { sum1=Integer.parseInt(text1.getText())*Integer.parseInt(text2.getText()); sum=String.valueOf(sum1); JOptionPane.showMessageDialog(null,sum,"RESULT",JOptionPane.INFORMATION_MESSAGE); } if(evt.getSource()==west) { sum1=Integer.parseInt(text1.getText())-Integer.parseInt(text2.getText()); sum=String.valueOf(sum1); JOptionPane.showMessageDialog(null,sum,"RESULT",JOptionPane.INFORMATION_MESSAGE); } if(evt.getSource()==south) { try { sum1=Integer.parseInt(text1.getText())/Integer.parseInt(text2.getText()); sum=String.valueOf(sum1); JOptionPane.showMessageDialog(null,sum,"RESULT",JOptionPane.INFORMATION_MESSAGE); } catch(ArithmeticException e) { JOptionPane.showMessageDialog(null,"DIVISION BY ZERO","RESULT",JOptionPane.WARNING_MESSAGE); } } } public static void main(String[] args) { grafika3 form=new grafika3(); form.setTitle("LESSON3"); form.setDefaultCloseOperation(EXIT_ON_CLOSE); form.setBounds(300,300,350,270); form.show(); } }