/* * @(#)Graph.java 1.9 99/08/04 * MODIFS PYL fev 2007!!!!!!!!!! * www.lmm.jussieu.fr/~lagree + py@cccr.jussieu.fr * * This software is designed and intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear facility. */ //javac guiBrachistochrone.java Kul.java ;java guiBrachistochrone //javac guiBrachistochrone.java Kul.java; jar cf guiBrachistochrone.jar *.class; open index.html import java.util.*; import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.net.*; class GraphPanel extends Panel implements Runnable, MouseListener { guiBrachistochrone graph; Kul kkul=new Kul(); public double dt0=0.001; Thread relaxer; public GraphPanel (){ } GraphPanel(guiBrachistochrone graph) { this.graph = graph; addMouseListener(this); } void initout() { System.out.println("init t=" + kkul.t +" ....................... dt =" +dt0); kkul.start(); } public void run() { Thread me = Thread.currentThread(); while (relaxer == me) { relax(); try { Thread.sleep(2); } catch (InterruptedException e) { break; } } } synchronized void relax() { repaint(); } Image offscreen; Dimension offscreensize; Graphics offgraphics; public synchronized void update(Graphics g) { Dimension d = getSize(); if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) { offscreen = createImage(d.width, d.height); offscreensize = d; if (offgraphics != null) { offgraphics.dispose(); } offgraphics = offscreen.getGraphics(); offgraphics.setFont(getFont()); } int offset=25; offgraphics.setColor(getBackground()); offgraphics.fillRect(0, 0, d.width, d.height); if(kkul.visi==1){ offgraphics.setColor(Color.green) ; for (int i = 1 ; i <= kkul.n ; i++) { offgraphics.drawLine(d.width/4+(i-1)*d.width/kkul.n/2, d.height*8/10-(int)(d.height*kkul.B[i-1]/2)- offset, d.width/4+ i* d.width/kkul.n/2, d.height*8/10-(int)(d.height*kkul.B[ i ]/2)- offset); }} offgraphics.setColor(Color.black) ; offgraphics.drawLine(d.width/4, d.height*8/10 - offset,(3*d.width)/4 , d.height*8/10 - offset); offgraphics.drawLine(d.width/4, d.height*8/10 - offset,d.width/4 , d.height*3/10 - offset); offgraphics.drawLine((3*d.width)/4, d.height*8/10- offset,(3*d.width)/4 , d.height*3/10- offset); offgraphics.drawLine(d.width/4, d.height*3/10- offset,(3*d.width)/4, d.height*3/10- offset); offgraphics.drawString(" T parcours="+ (((int)(kkul.Tfinal*100))/100.)+ " Record T="+ (((int)(kkul.Trecord*100))/100.) , 2*d.width/5, d.height/8); offgraphics.drawString("t="+(((int)(kkul.t*100))/100.)+" ", d.width/6, d.height/9); offgraphics.setColor(Color.red) ; for (int i = 1 ; i <= kkul.n ; i++) { offgraphics.drawLine(d.width/4+(i-1)*d.width/kkul.n/2, d.height*8/10-(int)(d.height*kkul.T[i-1]/2)- offset, d.width/4+ i* d.width/kkul.n/2, d.height*8/10-(int)(d.height*kkul.T[ i ]/2)- offset); } offgraphics.setColor(Color.black) ; offgraphics.drawString("x=0, y=0", d.width/6, 6*d.height/8); offgraphics.drawString("x=4, y=0", 6*d.width/8, 6*d.height/8); offgraphics.drawString("x=0, y=1", d.width/6, d.height/5); offgraphics.setColor(Color.blue) ; int ifr,jfr; double x=(d.width/4+((kkul.n*kkul.xp/kkul.Ldom))*d.width/kkul.n/2); double y=d.height*8/10-(int)(d.height*kkul.yp/2); ifr =(int)x; jfr =(int)y; // System.out.println("pressed "+ ifr + " " + jfr); // offgraphics.fillRect(ifr-2,jfr-2 - offset, 10, 10); offgraphics.fillArc(ifr-2,jfr-offset-8,8,8, 0,360); g.drawImage(offscreen, 0, 0, null); } //1.1 event handling public void mouseClicked(MouseEvent e) {} public void mousePressed(MouseEvent e) { int offset=25; if((e.getX()>getSize().width/4)&&(e.getX()<3*getSize().width/4)){ int iT=(e.getX()-getSize().width/4)*2*kkul.n/(getSize().width); double vT=-(e.getY()-getSize().height*8/10 + offset)*2.0/(getSize().height); int ii=15; if(iTkkul.ifinal-ii)ii=kkul.ifinal-iT; pt=(kkul.T[iT+ii]-vT)/(ii); for (int i = 1 ; i <= ii ; i++) { kkul.T[iT+i]=vT+ (i)*pt;} for (int i = 1 ; i < kkul.n ; i++) { kkul.To[i]=(kkul.T[i]); } for (int i = 1 ; i < kkul.n ; i++) { kkul.To[i]=kkul.To[i] + 0.07*(kkul.T[i-1]-2*kkul.T[i]+kkul.T[i+1]); } for (int i = 1 ; i < kkul.n ; i++) { kkul.T[i]=(kkul.To[i]); } ; System.out.println("pressed "+e.getX()+" "+e.getY()+" " +getSize().width/4/(getSize().width/kkul.n/2)); }} public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseDragged(MouseEvent e) {} public void mouseMoved(MouseEvent e) {} public void start() { relaxer = new Thread(this); relaxer.start(); } public void stop() { relaxer = null; } } public class guiBrachistochrone extends Applet implements ActionListener, ItemListener { public AudioClip sound0=null; GraphPanel panel; Panel controlPanel; JButton raz = new JButton("RAZ"); JButton calcul = new JButton("Calcul"); JButton pause = new JButton("Pause"); JButton razR = new JButton("RAZ Record"); JButton AB = new JButton("Affiche/Masque B."); JButton kit = new JButton("Quitte"); JLabel lab = new JLabel(" ", JLabel.CENTER) ; JTextField saizie= new JTextField ("0.000"); Choice choix = new Choice(); JLabel labo = new JLabel(" ", JLabel.CENTER) ; JTextField saizio= new JTextField ("4.000"); public void init() { setLayout(new BorderLayout()); panel = new GraphPanel(this); add("Center", panel); saizie.setText(""+panel.dt0); controlPanel = new Panel(); add("South", controlPanel); controlPanel.add(lab) ; lab.setText(" dt= ") ; controlPanel.add(saizie); raz.setLocation(10,10);raz.setSize(220,23); controlPanel.add(raz); raz.addActionListener(this); controlPanel.add(razR); razR.addActionListener(this); controlPanel.add(calcul); calcul.addActionListener(this); controlPanel.add(pause); pause.addActionListener(this); String champ="x final="; controlPanel.add(labo) ; labo.setText(champ) ; controlPanel.add(saizio); controlPanel.add(new JLabel("...", Label.RIGHT)); choix.addItemListener(this); controlPanel.add(AB); AB.addActionListener(this); controlPanel.add(kit); kit.addActionListener(this); panel.initout(); } public void destroy() { remove(panel); remove(controlPanel); } public void start() { razz(); panel.start(); } public void stop() { panel.stop(); } public void razz() { change_it(); panel.kkul.prems(); synchronized (panel.kkul) { panel.kkul.pleaseWait = true;}/////TRUE} change_it(); System.out.println("Init" ); } public void actionPerformed(ActionEvent e) { Object src = e.getSource(); if (src == razR){ System.out.println("RAZR"); panel.kkul.Trecord=9999.; } if (src == AB){ System.out.println("AB "+panel.kkul.visi); if(panel.kkul.visi==1){panel.kkul.visi=0;}else{panel.kkul.visi=1;} } if (src == raz) { razz(); System.out.println("RAZ, t=" + panel.kkul.t); return; } if (src == calcul) { String ch=saizie.getText(); double z =Double.parseDouble(ch); System.out.println("calcul, t=" + panel.kkul.t + "................dt =" + z ); panel.kkul.setdt(z); change_it(); synchronized (panel.kkul) { System.out.println("calcul"); panel.kkul.pleaseWait = false; panel.kkul.notify();} return; } if (src == pause) { synchronized (panel.kkul) { panel.kkul.pleaseWait = true;} } if (src == kit) { destroy(); System.out.println("kenavo"); System.exit(0) ; } } public void itemStateChanged(ItemEvent e) { change_it(); } public void change_it(){ int ined=choix.getSelectedIndex(); String ch=saizie.getText(); double z =Double.parseDouble(ch); ch=saizio.getText(); z =Double.parseDouble(ch); double zz; int iz; zz=2*z; iz=(int)zz; z=iz/2.; if(z>panel.kkul.Ldom){z=panel.kkul.Ldom;} System.out.println("param " + z ); panel.kkul.xfinal=z; ch=""+z; saizio.setText(ch); // labo.setText("T record....") ; } /////////////////////////////////////////////////////////// public static void main(String args[]) { JFrame f = new JFrame("guiBrachistochrone par PYL"); guiBrachistochrone guiBrachistochrone = new guiBrachistochrone(); //System.out.println(args[]); guiBrachistochrone.init(); guiBrachistochrone.start(); f.getContentPane().add("Center", guiBrachistochrone); f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE ) ; f.setSize(900, 300); f.setLocation(200, 200); f.show(); } public String getAppletInfo() { return "Calcul interactif par PYL. \n 'java guiGraph' \nou applet."; } }