import java(6) by hcj

VIEWS: 5 PAGES: 3

									import java.awt.*; import java.awt.event.*; import java.applet.*; class FenetreDeBase extends Frame { Panel panel1 = new Panel(); Button valide = new Button(); public FenetreDeBase(){ this.setSize(new Dimension(400,400));// taille de la fenetre valide.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { valide_actionPerformed(e); } }); panel1.add(valide, null); this.add(panel1,null); } void valide_actionPerformed(ActionEvent e){ this.dispose(); } } //-------------------------------------------------------class ChampNumerique extends TextField { public ChampNumerique() { this.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(KeyEvent e) { this_keyTyped(e); } }); } void this_keyTyped(KeyEvent e) { char c=e.getKeyChar(); if (c != KeyEvent.VK_BACK_SPACE && ( c <'0' || c >'9')) e.consume(); } } //--------------------------------------------------class MonDessin extends Canvas{ int m=0,k=0,w=400,h=200; public MonDessin() {} public void paint(Graphics g ){ int x0=w/2,y0=h/2, zoomy=h/2,zoomx=w/2; int x=0, y=0; // Axes g.drawLine(x0-zoomx, y0, x0+zoomx, y0); // axe x g.drawLine(x0, y0-zoomy, x0, y0+zoomy); // axe y // Sin(x) int x1=x0,y1=y0; for(int alfa=0; alfa<720; alfa++) { x = x0 + (int) (zoomx * Math.sin(m*Math.PI*alfa/360)); y = y0 + (int) (zoomy * Math.sin(k*Math.PI*alfa/360)); g.drawLine(x1, y1, x, y); x1=x;y1=y; } } } //---------------------------------------------------class Dialogue extends FenetreDeBase { ChampNumerique m = new ChampNumerique();

ChampNumerique k = new ChampNumerique(); Label label2 = new Label(); Label label1 = new Label(); public Dialogue() { k.setText("5"); m.setSize(new Dimension(21, 21)); m.setText("3"); setSize(new Dimension(400,100));// taille de la fenetre valide.setLabel("valider"); label2.setText("valeur de k"); label1.setText("valeur de m"); panel1.add(label1, null); panel1.add(m, null); panel1.add(label2, null); panel1.add(k, null); panel1.add(valide, null); this.add(panel1,null); } void valide_actionPerformed(ActionEvent e) { LeDscomplet.entrem.setText(m.getText()); LeDscomplet.entrek.setText(k.getText()); LeDscomplet.trace(); this.dispose(); } } //--------------------------------------------class Dessin extends FenetreDeBase{ Panel panel2=new Panel(); BorderLayout borderLayout1 = new BorderLayout(); MonDessin gg=new MonDessin(); public Dessin() { setLayout(borderLayout1); setSize(new Dimension(400,350));// taille de la fenetre setLocation(400,0); add(panel1,BorderLayout.SOUTH); add(gg,BorderLayout.CENTER); valide.setLabel("quitter"); } public void trace(int me,int ke){ gg.w=400;gg.h=200;gg.m=me;gg.k=ke; gg.repaint(); } } //-----------------------------------------------public class LeDscomplet extends Applet { BorderLayout borderLayout1 = new BorderLayout();// organise l'espace de l'applet // les 3 panels de l'applet static Panel jPanel1 = new Panel(); Panel jPanel2 = new Panel(); Panel jPanel3 = new Panel(); //composition de panel2 GridLayout gridLayout2 = new GridLayout();// organise l'espace de panel2 static TextField entrem = new TextField(); static TextField entrek = new TextField(); Label jLabel1 = new Label(); Label jLabel2 = new Label(); //composition de panel3 static Button execute = new Button();

//composition de panel1 static MonDessin jg=new MonDessin(); /**Construire l'applet*/ public LeDscomplet() { this.setSize(new Dimension(400,400)); // taille de l'applet this.setLayout(borderLayout1);// organise l'espace de l'applet //initialise composant de panel1 //taille du dessin jg.h=200; jg.w=300; jg.setBackground(Color.yellow); //compose panel1 jPanel1.add(jg,null); // Initialise les composants du panel2 jPanel2.setLayout(gridLayout2); jPanel2.setBackground(Color.pink); gridLayout2.setRows(2); gridLayout2.setColumns(2); entrem.setText("2"); entrek.setText("3"); jLabel1.setText("valeur de m"); jLabel2.setText("valeur de k"); //Compose panel2 jPanel2.add(entrem, null); jPanel2.add(entrek, null); jPanel2.add(jLabel1, null); jPanel2.add(jLabel2, null); // Initialise les composants de panel3 execute.setLabel("exécuter"); execute.addActionListener(new java.awt.event.ActionListener() {// gestion du bouton public void actionPerformed(ActionEvent e) { execute_actionPerformed(e); } }); //compose le panel3 organiseur de l'espace par défaut jPanel3.add(execute, null); //compose l'espace de l'applet add(jPanel1, BorderLayout.CENTER); add(jPanel2, BorderLayout.NORTH); add(jPanel3, BorderLayout.SOUTH); } void execute_actionPerformed(ActionEvent e) { // ouvrir le dialogue Dialogue f=new Dialogue(); f.show(); execute.setVisible(false); } public static void trace(){ execute.setVisible(true); int m=Integer.valueOf(entrem.getText()).intValue(); int k=Integer.valueOf(entrek.getText()).intValue(); jg.m=m; jg.k=k; jg.repaint(); Dessin d=new Dessin(); d.setVisible(true); d.trace(m,k); } }


								
To top