Caching Swings Graphics

I'm running a big application, with many screens (JPanels) on a slow system. The average time for the system to change screens is about 200ms. The first time you visit a screen, the average time to load is 400ms. Every time after that, its about 200ms. All of the screen are on top of each other, with setVisible(false) applied to all but the visible one. The only call made when changing screens is setVisible(false) and setVisible(true) (one to turn the previous screen off, the other to turn the new one on. I'm trying to find a way to get rid of that initial 400ms, and bring it down to 200ms. Is there anyway I can cache the graphics before the page is first visited?

Anyone?

Similar Messages

  • Swing graphics programming

    Hello everyone!! can you help;I am new to java programming. I have this project assignment to develop a small sofware that reads a file and use the data in the file to plot the graph, the prgm can read the file when the file name is entered but getting it to plot the graph, i am struggling with. please see the code below
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.geom.*;
    import java.awt.Graphics.*;
    import java.awt.Graphics2D.*;
    public class BioxSim extends JFrame {
         static Float a1=200F,a2=500F;//x
    static Float b1=200F,b2=75F;//y
    //JTextField to hold input data .
    private JTextField data_in;
    private JTextField data2_in;
    //JLabel to show output results.
    private JLabel degreesC;
    private JLabel fileLabel;
    //JTextArea to hold output results.
    private JTextArea ta;
    private FileReader readfile ;
    private BufferedReader buffer ;
    private JButton loadButton;
    private JButton plotButton;
    private JButton maths1;
    private JButton maths2;
    private JButton tempConversion;
    private JButton saveButton;
    private JButton clearButton;
    private String line;
    //Constructor for GoodDocs class - this method is used to set up the GUI
    public BioxSim() {
    // call the JFrame parent class with the window title
    super("Data Conversion");
    // we need the container for JFrames in order to add components
    Container container = getContentPane();
    FlowLayout flow = new FlowLayout();
         container.setLayout(flow);
         JLabel title = new JLabel("**************************************************************** Data Conversion Program *****************************************************");
         container.add(title, new BorderLayout().NORTH);
    //pos.gridx = 00; pos.gridy = 00;
    // container.add(title);
    // private label for the input units
    JLabel units = new JLabel("X, Y Data ");
    // private label to store prompt text
    JLabel prompt = new JLabel(" Input data for [X], [Y] coorinates ");
         JLabel fileLabel = new JLabel("File been Accessed is :" +line );
         // create an instance of the JLabel holding the output result
    degreesC = new JLabel("****************************** Example data: Input Degrees F; Output DegreesC Temp ******************************");
    // pos.gridx = 0; pos.gridy = 3;
    //container.add(prompt, pos);
    // create an instance of the JTextField for a specific number of columns
    data_in = new JTextField(15);
         data2_in = new JTextField("C: ", 18 );
         ta = new JTextArea(" The Output Data is Used to Plot the graph Below.", 3,62);
         loadButton = new JButton("Load File");     
    plotButton =new JButton("PlotGraph");
    maths1 = new JButton("Maths1");
    maths2 = new JButton("Maths2");
         tempConversion = new JButton("tempConversion");
    saveButton = new JButton("Save");
         clearButton = new JButton("Clear");
    //pos.gridx =0; pos.gridy = 6;
              container.add(degreesC);
    container.add(prompt);
    container.add(data_in);
              container.add(units);
              container.add(loadButton);
    container.add(data2_in);
              container.add(plotButton);
              container.add( maths1);
              container.add(maths2);
              container.add(tempConversion);
              container.add(saveButton);
    container.add(clearButton);
              container.add(fileLabel);
    container.add(ta);
              JScrollPane scroll = new JScrollPane(ta,
                   JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                   JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              container.add(scroll);
              CustomPanel panel = new CustomPanel();
              //Dimension dim = new Dimension(500, 400);
              //JPanel panel = new JPanel();
              panel.setPreferredSize( new Dimension(700,300));
    panel.setMinimumSize( new Dimension( 200, 100 ) );
              JScrollPane scroll1 = new JScrollPane(panel);
              container.add(scroll1);
    // register the TextField event handler - this is an inner class
    TextFieldHandler handler = new TextFieldHandler();
    data_in.addActionListener(handler);
    loadButton.addActionListener(handler);
    // set the applications size and make it visible
    setSize(800, 550);
    setVisible(true);
    class CustomPanel extends JPanel
    public void paintComponent (Graphics painter)
    painter.setColor(Color.white);
    painter.fillRect(0,0,getSize().width,getSize().height);
    Color customPurple = new Color(128,0,128);
    painter.setColor(customPurple);
    painter.drawString("graph",250,60);
    //Horizontal coordinate of the graph.
         Graphics2D X_line2D = (Graphics2D) painter;
    Line2D.Float X_line = new Line2D.Float(40F, 200F, 650F, 200F);
    X_line2D.draw(X_line);
    X_line2D.drawString("X coordinate", 50, 325);
    //Vertical coordinate of the graph.
    Graphics2D Y_line2D = (Graphics2D) painter;
    Line2D.Float Y_line = new Line2D.Float(200F, 450F, 200F, 20F);
    Y_line2D.draw(Y_line);
    //Line representing mathematical functions, where a[n],b[n] resp.are variables.
         Graphics2D Y1_line2D = (Graphics2D) painter;
         //graphdata(a2,b2);
    Line2D.Float Y1_line = new Line2D.Float(a1, b1, a2, b2);
    Y1_line2D.draw(Y1_line);
    //This method is used to execute the application */
    public static void main(String args[]) {
    // create an instance of our application
    BioxSim application = new BioxSim();
    // set the JFrame properties to respond to the window closing event
    application.setDefaultCloseOperation(
    JFrame.EXIT_ON_CLOSE );
    private String convertFtoC(String input) {
    //variables to store the real values of the Strings
    double tempF = 0.0;
    double tempC = 0.0;
    // use a try-catch block to contain data conversion exceptions
    try {
    // use the Double wrapper class to parse the string to a double
    tempF = Double.parseDouble(input);
    catch (NumberFormatException nfe) {
    // no need to do anything here - errors will leave tempF = 0.0
    // perform the conversion
    tempC = 5.0 / 9.0 * (tempF - 32.0);
    // return the result as a String
    return Double.toString(tempC);
    private String convertFtoC1(String input) {
    // variables to store the real values of the Strings
    double tempF = 0.0;
    double tempC = 0.0;
    // FileReadTest f = new FileReadTest();
    // f.readMyFile("input");
    // use a try-catch block to contain data conversion exceptions
    try {
    // use the Double wrapper class to parse the string to a double
    tempF = Double.parseDouble(input);
    catch (NumberFormatException nfe) {
    // no need to do anything here - errors will leave tempF = 0.0
    // perform the conversion
    tempC = tempF;//5.0 / 9.0 * (tempF - 32.0);
    // return the result as a String
    return Double.toString(tempC);
    /** Class TextFieldHandler implements ActionListner to provide the event handling
    for this application. It is a private inner class, which gives it access to
    all of the GoodDocs instance variables */
    private class TextFieldHandler implements ActionListener {
    /** This method is required for an ActionListener to process the events */
    public void actionPerformed(ActionEvent event) {
    String string = "";
              String filename = null;
    String taString;
    // The user pressed Enter in the JTextField textField1
    if(event.getSource() == data_in){
    // retrieve the input as a String
              // degreesC.setText("Input temperature is:" string "DegreeF");
    string = convertFtoC(event.getActionCommand());
              ta.setText(string);
    // The user pressed Enter in the JTextField textField1
    if(event.getSource() == loadButton)
              filename = string;
                   // retrieve the input as a String
         filename = data2_in.getText();
                   //fileLabel.setText("File been read is : " +filename );
         try
                        readfile = new FileReader(new File(filename));
                        buffer = new BufferedReader (readfile);
                        String lineRead = buffer.readLine();
                   //clears the imput area     
                   ta.setText("");
                        do
                        ta.append(lineRead+ "\n");
    while ((lineRead = buffer.readLine()) != null);
                   buffer.close();
                   catch (IOException e)
                        if(event.getSource() == clearButton){ 
                        ta.setText("");
    } // end of the private inner class TextFieldHandler
    } // end of public class GoodDocs
    DATA FILE e.g.
    Time[sec]     VD[g/m3]     VDFlux[g/m3h]     Flux[g/m2h]     AmbT[C]     AmbRH[%]     ProbeT[C]     ProbeRH[%]     CondenserT[C]     HeatsinkT[C]
    0     1.025237E-02     0     -108.264     16.7752     61.27579     23.63191     48.14857     23.30489     23.22949
    0.421     1.025237E-02     0     -108.264     16.7752     61.27579     23.63191     48.14857     23.30489     23.22949
    0.828     1.025237E-02     0     -108.264     16.7752     61.27579     23.63191     48.14857     23.30489     23.22949
    1.218     1.025581E-02     3.179105E-02     -108.229     16.7752     61.2831     23.63191     48.15666     23.30489     23.22949
    1.609     1.025891E-02     2.856279E-02     -108.1975     16.7752     61.28748     23.63191     48.16799     23.30489     23.22949
    1.968     1.025972E-02     8.050361E-03     -108.1893     16.7752     61.29041     23.63191     48.17554     23.30489     23.22949
    2.343     1.026729E-02

    Don't forget to use the "Code Formatting Tags",
    see http://forum.java.sun.com/help.jspa?sec=formatting,
    so the posted code retains its original formatting.

  • Accelerate swing graphics

    Hi All
    I'm currently working on a project that includes graphical representation using swing. I got some foreground-objects that move over a background. Unfortunately the performance is not as well as I expected. Perhaps there is a better approach for solving this problem:
    general idea:
    o) I use 3 images/grahics2d-objects of these images:
    one image contains the background picture
    one image contains the foreground picture
    one image is used as a offscreen buffer
    o) I draw the background picture over the offscreen buffer
    o) I draw the foreground picture also over the offscreen buffer
    o) Finally the offscreen buffer is written to the graphics-object
    the graphics are full-screen (1024x768). Is there a better way to do this?
    I would greatly appreciate any kind of help,
    exxion

    If its animation we talking about here. Use threads to do the animation calculation. But dont use too many threads, not wise to over use the power of threads.
    Try the code. Save it as japp.java. Fix the errors. Like image filenames. As i was rushing coding this.
    import java.awt.Graphics;
    import javax.swing.*;
    import java.awt.Image;
    class ImageBackgroundDraw extends Thread {
      JFrame app;
      int x;
      int y;
      public void setXY(int a, int b) {
        x = a;
        y = b;
      public drawImage(JFrame a, Image i) {
        this.app = a;
        x = 0;
        y = 0;
        start();
      public void run() {
        while (true) {
          // Update coordinates of image.
          // I dont know maybe x++;
          // Give it a little sleep we dont want it too fast
          if (x < app.w) x++
          try { sleep(app.sleep_duration); } catch (Exception e) { }
      public void paint(Graphics g) {
         Graphics2D g2 = (Graphics2D)g; 
         g2.drawImage(Image,x,y,app);
    public class japp extends javax.swing.JFrame implements Runnable {
        boolean initG = true;// Allow first Init of buffImgSurface
        private BufferedImage buffImg = null;
        private Graphics2D buffImgSurface;   
        private Thread appThread;
        public int w; // App height;
        public int h; // App width;
        ImageBackgroundDraw[] ibd = new ImageBackgroundDraw[2];
        Image back = new Image("back.gif");
        Image fore= new Image("fore.gif");
        long start = 0;             // Frame start time
        long tick_end_time;         // End frame time
        long tick_duration;         // Time taken to display the frame
        public long sleep_duration; // How long to sleep     
        static final int MIN_SLEEP_TIME = 10, // Min time to sleep for
                         MAX_FPS = 20,        // Max frame rate.  
                         MAX_MS_PER_FRAME=1000/MAX_FPS;// MS per frame
        float fps=0;  // Current frame rate
        public japp() {
          init();
          start();
        public void setWH(int a, int b) {
            w = a;
            h = b;
        public void init() {
          ibd[0] = new ImageBackgroundDraw(this,backgroundImage);
          ibd[1] = new ImageBackgroundDraw(this,ForgroundImage);
          ibd[3] = new ImageBackgroundDraw(this,ForgroundImage);
          ibd[0].setXY(0,0);
          ibd[1].setXY(0,0);
          ibd[1].setXY(0,0);
        public void update(Graphics g) {
          Graphics2D g2 = (Graphics2D)g; 
          // Erase graphics
          buffImgSurface.setBackground(Color.black);
          buffImgSurface.clearRect(0,0,w, h);
          for (int i=0; i < ibd.length; i++) {
            ibd.paint(buffImgSurface);
          g2.drawImage(buffImg,0,0,this);
        public void paint(Graphics g) {
          if (initG == true) {           
                buffImg = (BufferedImage)createImage(w,h);
                buffImgSurface = buffImg.createGraphics();   
                initG = false;
        public void start() {
            if (appThread == null) {
                appThread = new Thread(this, "app");
                appThread.start();
        public void run() {
          // While this thread is active and running keep repeating
          while (true) {
            start = System.currentTimeMillis();
            repaint();
            tick_end_time=System.currentTimeMillis();
            tick_duration=tick_end_time - start;
            if (sleep_duration < MIN_SLEEP_TIME) {
              sleep_duration=MIN_SLEEP_TIME;
            fps = 1000 / (sleep_duration + tick_duration);
    }If you like g.drawString("FPS"+fps,1,10); to show FPS to see if there is any improvement. Otherwise try JNI!(Java Native Interface) Coding and make up your own graphic routines for your applications. You can program your Java API in Assembly with JNI!.

  • Swing Graphics

    You'll have to forgive me for my ignorance. I'm just learning Swing but I'm used to .NET where it is quite easy to add your own PaintHandlers.
    For example, my main JFrame consists of 3 panels - 1 main panel to control the layout, and 2 other panels which are on this panel.
    I would like to be able to control the graphics context for one of the panels., so in the paintComponents(g) method, I simply have this:
    Graphics2D g2d = (Graphics2D)gamePanel.getGraphics();
    g2d.drawRectangle(100,100,100,100);
    Now why will something as simple as this not work? My panel is still blank.
    Or how do I force the paintComponents method to be called from another method??
    Thanks for any help!!

    That's about exactly what I have and it still isn't painting.
    private class MyPanel extends JPanel {
              public MyPanel (GameGUI mainWin) {
                   setSize(100,mainWin.HEIGHT);
                   setBorder(BorderFactory.createEmptyBorder(30, 30, 10, 30));
                   setBackground(Color.white);
                   setLayout(new GridLayout(0, 1));                         
              public void paintComponents(Graphics g) {
                   super.paintComponents(g);
                   Graphics2D g2d = (Graphics2D)g;
                   g2d.setColor(Color.black);
                   g2d.fillRect(100,100,100,100);
                   g.setColor(Color.black);          
    g.drawRect(10,10,100,100);
    I must be doing something else wrong!

  • Swing & Graphics Integration

    ��I have a need for a specialized graphics editor. I can build the GUI and I can draw graphics; but, I'm not sure how to integrate the two. Specifically, modelling the graphic components. i.e. 2 points make a line. I'd like to instantiate a Line() object whose endpoints respond to mouse dragging, and maybe a double click to edit it's properties.
    ��Any suggestions or related references would be greatly appreciated.
    Thanks,
    Jon

    ��I have a need for a specialized graphics editor. I can build the GUI and I can draw graphics; but, I'm not sure how to integrate the two. Specifically, modelling the graphic components. i.e. 2 points make a line. I'd like to instantiate a Line() object whose endpoints respond to mouse dragging, and maybe a double click to edit it's properties.
    ��Any suggestions or related references would be greatly appreciated.
    Thanks,
    Jon

  • Performance with Swing graphics...

    Hey all, I have a small 2d multiplayer game that I'm writing in Java. The trouble is that, despite it being simple, it runs pretty slow. I have a few theories about things that I might should do to speed it up, and I wanted to know if you guys agreed with me and if, perhaps, i fell into some sort of newbie pitfall that I didn't notice...
    1.) Running all the clients and server off of one machine. I suspect this is one good reason why it runs so slow, but my system is good (a new 1.5ghz G4 PowerBook with a gig of RAM) and I haven't gotten a chance to fire up everything on separate machines. Could it be that running 3 windows updated every 100ms is the only problem? :)
    2.) Not getting the UI's running on the event dispatching thread. I know, this is a big no-no and I have to do it regardless, but does it affect the performance?
    3.) Elliptical clipping of the viewport. The game shows a circle around each player, does clipping the view in this way hinder the speed?
    4.) Collections! I discovered the collections framework recently and have the game objects organized into Java collections. In theory, though, once the game starts, there's no need to add more game objects (so they don't need to grow dynamically). I'm wondering if it would be faster to read in everything at the beginning into a collection, then convert it to an array before the game starts and just use that the whole time.
    5.) Alpha blending. I have a few translucent objects in the view. Should these be eliminated? It does seem to run a bit faster with them gone. I have some weird ghost translucent objects that I'm trying to track down, so I suspect that'll cut the number of translucent things in half, which should give a speed boost.
    I'm sure it's difficult to tell for sure without the code, but the programs are pretty big and the questions are general. Any assistance would be greatly appreciated.
    In the meantime, I'll continue hunting for performance discussions and working on the code!
    Thanks!
    -Zach

    run a profiler. this should help you determine where the bottleneck is.
    1.) Running all the clients and server off of one machine. i'm assuming that the server will be put on a different machine when your app goes into production. but during testing, unless your server do a lot of stuff , then it should not matter.
    Could it be that running 3 windows updated every 100ms is the only problem? :not sure by what you mean Window update?
    2.) Not getting the UI's running on the event dispatching thread. I know, this is a
    big no-no and I have to do it regardless, but does it affect the performance?yes..it's a big-no-no!! how do you paint the UI? the great thing about th eevent dispatcher is that when you issue multiple repaint(), it does not paint each time..rather..it check a flag to see if a repaint is need..and then repaint th ecomponent. so, it may just repaint once. if you repaint manually..you may do this multiple time...which could slow down your application. Just beware of doing anything in the event dispatcher thread that could slow down your app or even lock th eGUI components.
    4.) Collections! .. 'm wondering if it would be faster to read in everything at the
    beginning into a collection, then convert it to an array before the game starts if this is the case..yes, using array would be faster, since th elookup is determined using th ebase address multiplied by the index and the size of th eelement. for object array..the size of the element is the adress where th eobject reside in the heap.

  • Disappearing Graphics in Jpanels!

    Hi all,
    I am new to java and have a slight problem. I have two forms, one is my main form and the other is used for a settings option for changing various aspects of my program such as colours etc.
    On my main form I have 2 jPanels - one that shows my main image (it's a graph that I've created and used BufferImage to then draw it on the jPanel. The other shows a smaller version of this using similar method but scale the original image to make it smaller.
    I have a function called drawStuff which draws all the main graphs, one called drawScales which draws all the axis labels and small graphs. I called upon these when I want them to be drawn. I don't use paint() or paintcomponent() etc.
    My problem is that whenever I open my settings menu, the settings form appears over my jpanel, like it should, but all of a sudden all the images on both jpanels dissapear! so when I exit the settings menu both panels are empty! I want them to stay the way they are until I redraw them!
    public void drawStuff()
      Graphics2D l = (Graphics2D)g;         
               if (window==0){
               if ((mpress=true)| (bpre==1)){
               bpre=0;
               h.setColor(Color.white);
               h.fillRect(0,0,661,352);
               h.setColor(Color.white);
               h.fillRect(0,0,661,352);      
               h.setColor(Color.black);
               h.drawLine(0,0,0,351); // draw graph axis
               h.drawLine(0,351,661,351);
               h.setColor(jPanel9.getBackground());
               h.fillRect(1,0,660,351);
               h.setColor(jPanel10.getBackground());
               int temp=scalep;
                while (1+scalep+swp<661){
                h.fillRect((1+scalep),0,swp,351);
                scalep=scalep+swp+swp;
               if (1+scalep<661){
                h.fillRect(scalep,0,660,351);  
               scalep=temp;
               GetCols(5);
               int psize=jSlider8.getValue();
               for (int o=1;o<nolin+1;o++){   
                    if (zdata[o][1][zomlev]==1){
                        zdata[o][1][zomlev+1]=0;
                         h.fillRect(660-test1[o][1],0+test1[o][2],psize,psize);
               g.drawImage(Buffer,75,30,this);
               xl=0;
               xr=0;
               yl=0;
               yr=0;
             if (mdrag==true){
                  g.drawImage(Buffer,75,30,this);
                  g.setColor(Color.black);
                  l.setColor (Color.black);
                  l.setStroke(dashed);
                 //bottom right
                 if ((selx1 < selx2) & (sely1 < sely2)){
                 //g.setColor(Color.black);     
                 //g.drawRect(selx1, sely1, selx2-selx1, sely2-sely1);
                  g.drawRect(selx1, sely1,selx2-selx1, sely2-sely1);
                  //l.draw(rectangle);
                 xl=selx1;
                 xr=selx2;
                 yl=sely1;
                 yr=sely2;
                 //bottom left
                 if ((selx1 > selx2) & (sely1 < sely2)){
                 g.drawRect(selx2, sely1,selx1-selx2, sely2-sely1);
                 xl=selx2;
                 xr=selx1;
                 yl=sely1;
                 yr=sely2;
                 //top left
                 if ((selx1 > selx2) & (sely1 > sely2)){
                 g.drawRect(selx2, sely2,selx1-selx2, sely1-sely2);
                 xl=selx2;
                 xr=selx1;
                 yl=sely2;
                 yr=sely1;
                 //top right
                  if ((selx1 < selx2) & (sely1 > sely2)){
                 g.drawRect(selx1, sely2,selx2-selx1, sely1-sely2);
                 xl=selx1;
                 xr=selx2;
                 yl=sely2;
                 yr=sely1;
                 GetCols(4);
                 int psize=jSlider8.getValue();
                  for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((735-test1[o][1]>xl) & (735-test1[o][1]<xr) & (30+test1[o][2]>yl) & (30+test1[o][2]<yr)){               
                         g.fillRect(735-test1[o][1],30+test1[o][2],psize,psize);
                         zdata[o][1][zomlev+1]=1;
             sxl=xl;
             sxr=xr;
             syl=yl;
             syr=yr;
             l.setStroke(stroke);
               /*if ((nbox==1) | (red==0)){
               g.setColor(Color.white);
               g.fillRect(3,16, 764, 401);
               g.setColor(Color.black);
               g.drawLine(75,380,725,380); // draw graph axis
               g.drawLine(75,380,75,30);
               //timescale();
               //timetwofour();
               g.drawString(twofours,50,400);
               String minyS=String.valueOf(miny);
               g.drawString(minyS,10,380);
               g.drawString(twofoure,705,400);
               String maxyS=String.valueOf(maxy);
               g.drawString(maxyS,10,40);
               g.drawString("Peak Energy",5,205);
               g.drawString("Time of Signal",400,400);
           if (nbox==1){
                 g.setColor(Color.white); // clear previous box
                 g.fillRect(xl, yl, xr-xl+1, yr-yl+1);
                 for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((725-test1[o][1]>xl) & (725-test1[o][1]<xr) & (30+test1[o][2]>yl) & (30+test1[o][2]<yr)){
                         g.setColor(Color.lightGray);                
                         g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
                 nbox=0;
                 xl=0;
                 xr=0;
                 yl=0;
                 yr=0;
             if (red==1){
               g.setColor(Color.black);
               g.drawLine(75,380,725,380); // draw graph axis
               g.drawLine(75,380,75,30);
                 //bottom right
                 if ((selx1 < selx2) & (sely1 < sely2)){
                 if (sxl>0){
                 g.setColor(Color.white);
                 g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
                 for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((725-test1[o][1]>sxl-3) & (725-test1[o][1]<sxr+3) & (30+test1[o][2]>syl-3) & (30+test1[o][2]<syr+3)){
                         g.setColor(Color.lightGray);                
                         g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
                 g.setColor(Color.black);
                 g.drawRect(selx1, sely1,selx2-selx1, sely2-sely1);
                 g.setColor(Color.white);
                 g.fillRect(selx1+1, sely1+1, selx2-selx1-1, sely2-sely1-1);
                 xl=selx1;
                 xr=selx2;
                 yl=sely1;
                 yr=sely2;
                 //bottom left
                 if ((selx1 > selx2) & (sely1 < sely2)){
                 if (sxl>0){
                 g.setColor(Color.white);
                 g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
                 for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((725-test1[o][1]>sxl-4) & (725-test1[o][1]<sxr+4) & (725-test1[o][2]>syl-4) & (30+test1[o][2]<syr+4)){
                         g.setColor(Color.lightGray);                
                         g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
                 g.setColor(Color.black);
                 g.drawRect(selx2, sely1,selx1-selx2, sely2-sely1);
                 g.setColor(Color.white);
                 g.fillRect(selx2+1, sely1+1, selx1-selx2-1, sely2-sely1-1);
                 xl=selx2;
                 xr=selx1;
                 yl=sely1;
                 yr=sely2;
                 //top left
                 if ((selx1 > selx2) & (sely1 > sely2)){
                 if (sxl>0){
                 g.setColor(Color.white);
                 g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
                 for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((725-test1[o][1]>sxl-4) & (725-test1[o][1]<sxr+4) & (30+test1[o][2]>syl-4) & (30+test1[o][2]<syr+4)){
                         g.setColor(Color.lightGray);                
                         g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
                 g.setColor(Color.black);
                 g.drawRect(selx2, sely2,selx1-selx2, sely1-sely2);
                 g.setColor(Color.white);
                 g.fillRect(selx2+1, sely2+1, selx1-selx2-1, sely1-sely2-1);
                 xl=selx2;
                 xr=selx1;
                 yl=sely2;
                 yr=sely1;
                 //top right
                  if ((selx1 < selx2) & (sely1 > sely2)){
                 if (sxl>0){
                 g.setColor(Color.white);
                 g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
                 for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((725-test1[o][1]>sxl-4) & (725-test1[o][1]<sxr+4) & (30+test1[o][2]>syl-4) & (30+test1[o][2]<syr+4)){
                         g.setColor(Color.lightGray);                
                         g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
                 g.setColor(Color.black);
                 g.drawRect(selx1, sely2,selx2-selx1, sely1-sely2);
                 g.setColor(Color.white);
                 g.fillRect(selx1+1, sely2+1, selx2-selx1-1, sely1-sely2-1);
                 xl=selx1;
                 xr=selx2;
                 yl=sely2;
                 yr=sely1;
                 for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((725-test1[o][1]>xl) & (725-test1[o][1]<xr) & (30+test1[o][2]>yl) & (30+test1[o][2]<yr)){
                         g.setColor(Color.blue);                
                         g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
             sxl=xl;
             sxr=xr;
             syl=yl;
             syr=yr;
             if (window==0){
                 for (int o=1;o<nolin+1;o++){
                     if (red==0){
                         if (zdata[o][1][zomlev]==1){
                         g.setColor(Color.lightGray);                
                         g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
                     //if (red==0){
                    // if (data[o][1]==1){
                    // if (((540-test1[o][1])<selx2) && ((540-test1[o][1])>selx1) && ((380-test1[o][2])>sely1) && ((380-test1[o][2])<sely2)){
                     //       g.setColor(new java.awt.Color(200, 200, 200));}
                 //   g.fillOval(540-test1[o][1],380-test1[o][2],2,2);   
          /*if (window==1){
               if ((nbox==1) | (red==0)){
               g.setColor(Color.white);
               g.fillRect(3,16, 764, 401);
               g.setColor(Color.black);
               g.drawLine(75,zeroy,725,zeroy); //  y zero axis
               g.drawLine(zerox,30,zerox,380); // x zero axis
               String minxS="0";
               g.drawString(minxS,zerox,400);
               String minyS="0";
               g.drawString(minyS,10,zeroy);
               g.drawString("Log 10 R",10,205);
               g.drawString("Difference in Time of Flight",400,400);
           if (nbox==1){
                 g.setColor(Color.white); // clear previous box
                 g.fillRect(xl, yl, xr-xl+1, yr-yl+1);
                 for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((725-test1[o][1]>xl) & (725-test1[o][1]<xr) & (30+test1[o][2]>yl) & (30+test1[o][2]<yr)){
                         g.setColor(Color.lightGray);                
                         g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
                 nbox=0;
                 xl=0;
                 xr=0;
                 yl=0;
                 yr=0;
             if (red==1){
               g.setColor(Color.black);
               g.drawLine(75,zeroy,725,zeroy); //  y zero axis
               g.drawLine(zerox,30,zerox,380); // x zero axis
                 //bottom right
                 if ((selx1 < selx2) & (sely1 < sely2)){
                 if (sxl>0){
                 g.setColor(Color.white);
                 g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
                 for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((725-test1[o][1]>sxl-3) & (725-test1[o][1]<sxr+3) & (30+test1[o][2]>syl-3) & (30+test1[o][2]<syr+3)){
                         g.setColor(Color.lightGray);                
                         g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
                 g.setColor(Color.black);
                 g.drawRect(selx1, sely1,selx2-selx1, sely2-sely1);
                 g.setColor(Color.white);
                 g.fillRect(selx1+1, sely1+1, selx2-selx1-1, sely2-sely1-1);
                 xl=selx1;
                 xr=selx2;
                 yl=sely1;
                 yr=sely2;
                 //bottom left
                 if ((selx1 > selx2) & (sely1 < sely2)){
                 if (sxl>0){
                 g.setColor(Color.white);
                 g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
                 for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((725-test1[o][1]>sxl-4) & (725-test1[o][1]<sxr+4) & (725-test1[o][2]>syl-4) & (30+test1[o][2]<syr+4)){
                         g.setColor(Color.lightGray);                
                         g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
                 g.setColor(Color.black);
                 g.drawRect(selx2, sely1,selx1-selx2, sely2-sely1);
                 g.setColor(Color.white);
                 g.fillRect(selx2+1, sely1+1, selx1-selx2-1, sely2-sely1-1);
                 xl=selx2;
                 xr=selx1;
                 yl=sely1;
                 yr=sely2;
                 //top left
                 if ((selx1 > selx2) & (sely1 > sely2)){
                 if (sxl>0){
                 g.setColor(Color.white);
                 g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
                 for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((725-test1[o][1]>sxl-4) & (725-test1[o][1]<sxr+4) & (30+test1[o][2]>syl-4) & (30+test1[o][2]<syr+4)){
                         g.setColor(Color.lightGray);                
                         g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
                 g.setColor(Color.black);
                 g.drawRect(selx2, sely2,selx1-selx2, sely1-sely2);
                 g.setColor(Color.white);
                 g.fillRect(selx2+1, sely2+1, selx1-selx2-1, sely1-sely2-1);
                 xl=selx2;
                 xr=selx1;
                 yl=sely2;
                 yr=sely1;
                 //top right
                  if ((selx1 < selx2) & (sely1 > sely2)){
                 if (sxl>0){
                 g.setColor(Color.white);
                 g.fillRect(sxl-2, syl-2, sxr-sxl+4, syr-syl+4);//all
                 for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((725-test1[o][1]>sxl-4) & (725-test1[o][1]<sxr+4) & (30+test1[o][2]>syl-4) & (30+test1[o][2]<syr+4)){
                         g.setColor(Color.lightGray);                
                         g.fillOval(725-test1[o][1],30+test1[o][2],2,2);
                 g.setColor(Color.black);
                 g.drawRect(selx1, sely2,selx2-selx1, sely1-sely2);
                 g.setColor(Color.white);
                 g.fillRect(selx1+1, sely2+1, selx2-selx1-1, sely1-sely2-1);
                 xl=selx1;
                 xr=selx2;
                 yl=sely2;
                 yr=sely1;
                 for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((725-test1[o][1]>xl) & (725-test1[o][1]<xr) & (30+test1[o][2]>yl) & (30+test1[o][2]<yr)){
                         g.setColor(Color.red);
                         g.fillOval(725-zerox+test1[o][1],30+zeroy-test1[o][2],2,2);
                     if ((725-test2[o][1]>xl) & (725-test2[o][1]<xr) & (30+test2[o][2]>yl) & (30+test2[o][2]<yr)){
                         g.setColor(Color.blue);
                         g.fillOval(725-zerox+test2[o][1],30+zeroy-test2[o][2],2,2);
                    if ((725-test3[o][1]>xl) & (725-test3[o][1]<xr) & (30+test3[o][2]>yl) & (30+test3[o][2]<yr)){
                    g.setColor(Color.green);
                   g.fillOval(725-zerox+test3[o][1],30+zeroy-test3[o][2],2,2);   
             sxl=xl;
             sxr=xr;
             syl=yl;
             syr=yr;
             if (window==1){ 
             //plot points depending on choosen sets of data 
             if ((cho==1) | (cho==4) | (cho==5) | (cho==7)){
             for (int o=1;o<nolin+1;o++){
                 if (zdata[o][1][zomlev]==1){ 
                 g.setColor(Color.red);
                   g.fillOval(zerox+test1[o][1],zeroy-test1[o][2],2,2);   
             if ((cho==2) | (cho==4) | (cho==6) | (cho==7)){
             for (int o=1;o<nolin+1;o++){
                 if (zdata[o][1][zomlev]==1){ 
                 g.setColor(Color.blue);
                   g.fillOval(zerox+test2[o][1],zeroy-test2[o][2],2,2);   
             if ((cho==3) | (cho==5) | (cho==6) | (cho==7)){
             for (int o=1;o<nolin+1;o++){
                 if (zdata[o][1][zomlev]==1){
                 g.setColor(Color.green);
                   g.fillOval(zerox+test3[o][1],zeroy-test3[o][2],2,2);   
        // =========  START HERE FOR SENSOR PAIRS ===============
           if (window==1){
               if ((mpress=true)| (bpre==1)){
               bpre=0;   
               h.setColor(Color.white);
               h.fillRect(0,0,661,352);
               h.setColor(Color.black);
               h.setColor(jPanel9.getBackground());
               h.fillRect(0,0,661,352);
               h.setColor(jPanel10.getBackground());
               scale=0;
               int factor=0;
               if (jRadioButton13.isSelected()==true){
                    factor=5;
                if (jRadioButton14.isSelected()==true){
                    factor=10;
                if (jRadioButton15.isSelected()==true){
                    factor=30;
                if (jRadioButton16.isSelected()==true){
                    factor=60;
               sw=(int)(factor/divfx);
               while (1+scale+sw<661){
               h.fillRect((1+scale+zerox),0,sw,352);
               scale=scale+sw+sw;
               if (1+scale<661){
               h.fillRect((1+scale+zerox),0,661,352); 
               scale=zerox;
               while (scale-sw-sw>0){
               h.fillRect((scale-sw-sw),0,sw,352);
               scale=scale-sw-sw;
               if (scale-sw>0){
               h.fillRect(0,0,scale-sw,352); 
               //if (1+scale<661){
               //h.fillRect(scale,0,660,351);  
               h.setColor(Color.black);
               h.drawLine(0,zeroy,661,zeroy); //  y zero axis
               h.drawLine(zerox,0,zerox,381); // x zero axis
             int psize=jSlider1.getValue();
             if ((cho==1) | (cho==4) | (cho==5) | (cho==7)){
              GetCols(6);
                 for (int o=1;o<nolin+1;o++){
                 if (zdata[o][1][zomlev]==1){
                   zdata[o][1][zomlev+1]=0; 
                   h.fillRect(zerox+test1[o][1],zeroy-test1[o][2],psize,psize);   
             if ((cho==2) | (cho==4) | (cho==6) | (cho==7)){
                  GetCols(7);
                 for (int o=1;o<nolin+1;o++){
                 if (zdata[o][1][zomlev]==1){ 
                   zdata[o][1][zomlev+1]=0;
                   h.fillRect(zerox+test2[o][1],zeroy-test2[o][2],psize,psize);   
             if ((cho==3) | (cho==5) | (cho==6) | (cho==7)){
             GetCols(8);
                 for (int o=1;o<nolin+1;o++){
                 if (zdata[o][1][zomlev]==1){
                   zdata[o][1][zomlev+1]=0;
                   h.fillRect(zerox+test3[o][1],zeroy-test3[o][2],psize,psize);   
               xl=0;
               xr=0;
               yl=0;
               yr=0;
                g.drawImage(Buffer,75,30,this);
             if (mdrag==true){
               g.drawImage(Buffer,75,30,this);
                  g.setColor(Color.black);
                  l.setColor (Color.black);
                  l.setStroke(dashed);
                 //bottom right
                 if ((selx1 < selx2) & (sely1 < sely2)){
                 //g.setColor(Color.black);     
                 //g.drawRect(selx1, sely1, selx2-selx1, sely2-sely1);
                  g.drawRect(selx1, sely1,selx2-selx1, sely2-sely1);
                  //l.draw(rectangle);
                 xl=selx1;
                 xr=selx2;
                 yl=sely1;
                 yr=sely2;
                 //bottom left
                 if ((selx1 > selx2) & (sely1 < sely2)){
                 g.drawRect(selx2, sely1,selx1-selx2, sely2-sely1);
                 xl=selx2;
                 xr=selx1;
                 yl=sely1;
                 yr=sely2;
                 //top left
                 if ((selx1 > selx2) & (sely1 > sely2)){
                 g.drawRect(selx2, sely2,selx1-selx2, sely1-sely2);
                 xl=selx2;
                 xr=selx1;
                 yl=sely2;
                 yr=sely1;
                 //top right
                  if ((selx1 < selx2) & (sely1 > sely2)){
                 g.drawRect(selx1, sely2,selx2-selx1, sely1-sely2);
                 xl=selx1;
                 xr=selx2;
                 yl=sely2;
                 yr=sely1;
             int psize=jSlider1.getValue();
             if ((cho==1) | (cho==4) | (cho==5) | (cho==7)){
              GetCols(9);
                 for (int o=1;o<nolin+1;o++){
                 if (zdata[o][1][zomlev]==1){
                     if ((75+zerox+test1[o][1]>xl) & (75+zerox+test1[o][1]<xr) & (30+zeroy-test1[o][2]>yl) & (30+zeroy-test1[o][2]<yr)){
                     g.fillRect(75+zerox+test1[o][1],30+zeroy-test1[o][2],psize,psize);   
                     zdata[o][1][zomlev+1]=1;
             if ((cho==2) | (cho==4) | (cho==6) | (cho==7)){
                  GetCols(12);
                 for (int o=1;o<nolin+1;o++){
                 if (zdata[o][1][zomlev]==1){ 
                 if ((75+zerox+test2[o][1]>xl) & (75+zerox+test2[o][1]<xr) & (30+zeroy-test2[o][2]>yl) & (30+zeroy-test2[o][2]<yr)){
                   g.fillRect(75+zerox+test2[o][1],30+zeroy-test2[o][2],psize,psize);   
               zdata[o][1][zomlev+1]=1;
             if ((cho==3) | (cho==5) | (cho==6) | (cho==7)){
             GetCols(13);
                 for (int o=1;o<nolin+1;o++){
                 if (zdata[o][1][zomlev]==1){
                 if ((75+zerox+test3[o][1]>xl) & (75+zerox+test3[o][1]<xr) & (30+zeroy-test3[o][2]>yl) & (30+zeroy-test3[o][2]<yr)){
                   g.fillRect(75+zerox+test3[o][1],30+zeroy-test3[o][2],psize,psize);   
                 zdata[o][1][zomlev+1]=1;
             sxl=xl;
             sxr=xr;
             syl=yl;
             syr=yr;
             l.setStroke(stroke);
           // =========  START HERE FOR PHASE ===============
           if (window==2){
               if ((mpress=true)| (bpre==1)){
               bpre=0;   
               h.setColor(Color.white);
               h.fillRect(0,0,661,352);
               h.setColor(jPanel9.getBackground());
               h.fillRect(1,0,165,351);
               h.fillRect(331,0,165,351);
               h.setColor(jPanel10.getBackground());
               h.fillRect(166,0,165,351);
               h.fillRect(496,0,165,351);
               h.setColor(Color.black);
               h.drawLine(0,0,0,351); // draw graph axis
               h.drawLine(0,351,661,351);
               GetCols(11);
               int psize=jSlider9.getValue();
                 for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                         zdata[o][1][zomlev+1]=0;
                         h.fillRect(660-test1[o][1],0+test1[o][2],psize,psize);
               xl=0;
               xr=0;
               yl=0;
               yr=0;
                g.drawImage(Buffer,75,30,this);
             if (mdrag==true){
               g.drawImage(Buffer,75,30,this);
                  g.setColor(Color.black);
                  l.setColor (Color.black);
                  l.setStroke(dashed);
                 //bottom right
                 if ((selx1 < selx2) & (sely1 < sely2)){
                 //g.setColor(Color.black);     
                 //g.drawRect(selx1, sely1, selx2-selx1, sely2-sely1);
                  g.drawRect(selx1, sely1,selx2-selx1, sely2-sely1);
                  //l.draw(rectangle);
                 xl=selx1;
                 xr=selx2;
                 yl=sely1;
                 yr=sely2;
                 //bottom left
                 if ((selx1 > selx2) & (sely1 < sely2)){
                 g.drawRect(selx2, sely1,selx1-selx2, sely2-sely1);
                 xl=selx2;
                 xr=selx1;
                 yl=sely1;
                 yr=sely2;
                 //top left
                 if ((selx1 > selx2) & (sely1 > sely2)){
                 g.drawRect(selx2, sely2,selx1-selx2, sely1-sely2);
                 xl=selx2;
                 xr=selx1;
                 yl=sely2;
                 yr=sely1;
                 //top right
                  if ((selx1 < selx2) & (sely1 > sely2)){
                 g.drawRect(selx1, sely2,selx2-selx1, sely1-sely2);
                 xl=selx1;
                 xr=selx2;
                 yl=sely2;
                 yr=sely1;
                 GetCols(10);
                 int psize=jSlider9.getValue();
                  for (int o=1;o<nolin+1;o++){
                     if (zdata[o][1][zomlev]==1){
                     if ((735-test1[o][1]>xl) & (735-test1[o][1]<xr) & (30+test1[o][2]>yl) & (30+test1[o][2]<yr)){               
                         g.fillRect(735-test1[o][1],30+test1[o][2],psize,psize);
                         zdata[o][1][zomlev+1]=1;
             sxl=xl;
             sxr=xr;
             syl=yl;
             syr=yr;
             l.setStroke(stroke);
    public void drawscales(){
        Font font1 = new Font("TW Cen MT", Font.BOLD,12);
        Font font2 = new Font("TW Cen MT",Font.PLAIN,10);
        Font font3 = new Font("TW Cen MT",Font.BOLD,10);
        g.setColor(Color.white);
        g.fillRect(2,2, 764, 409);
        g.setColor(Color.black); 
        if (window==0){
               g.setFont(font2);
               g.drawString(twofours,52,400);
               String minyS=String.valueOf(miny);
               g.drawString(minyS,50,383);
               g.drawString(twofoure,712,400);
               String maxyS=String.valueOf(may);
               g.drawString(maxyS,50,33);
               g.setFont(font1);
               g.drawString("Energy againt Time Graph",330,20);
               g.setFont(font3);
               g.drawString("Peak Energy",10,205);
               g.drawString("/ pJ",30,217);
               g.drawString("Time of Signal",370,400);  
               /*h.setColor(Color.black);
               h.drawLine(0,0,0,351); // draw graph axis
               h.drawLine(0,351,661,351);
               h.setColor(jPanel9.getBackground());
               h.fillRect(1,0,660,351);
               h.setColor(jPanel10.getBackground());
                while (1+scale+sw<661){
                h.fillRect((1+scale),0,sw,351);
                scale=scale+sw+sw;
               if (1+scale<661){
                h.fillRect(scale,0,660,351);  
               for (int o=1;o<nolin+1;o++){
                   GetCols(5);
                     if (zdata[o][1][zomlev]==1){
                         int psize=jSlider8.getValue();
                         h.fillRect(660-test1[o][1],0+test1[o][2],psize,psize);
               //g.drawImage(Buffer,75,30,this);
               sma.drawImage(smallpow,1,1,jPanel2);
               double ndf =((zmpmr-zmpml)/219);
               double ndyf=((zmpmt-zmpmb)/116);
               int wdp=(int)((dmax-dmix)/ndf);
               int htp=(int)((may-miy)/ndyf);
               int sx=(int)((dmix-zmpml)/ndf);
               int sy=(int)((zmpmt-may)/ndyf);
               sma.drawRect(1+sx,1+sy,wdp,htp);
        if (window==1){
               g.setColor(Color.black);
               g.setFont(font2);
               String minxS="0";
               g.drawString(minxS,zerox+72,395);
               String minyS="0";
               g.drawString(minyS,65,zeroy+34);
               g.setFont(font3);
               g.drawString("Log 10 R /",9,200);
               g.drawString("Ratio of",13,212);
               g.drawString("Energy",13,224);
               g.drawString("Difference in Time of Flight / Seconds",315,408);
               g.setFont(font1);
               g.drawString("Sensor Pairs Graph",350,20);
              /* h.setColor(Color.white);
               h.fillRect(0,0,661,352);
               h.setColor(Color.black);
               h.setColor(new java.awt.Color(240, 240, 255));
               h.fillRect(0,0,661,352);
               h.setColor(new java.awt.Color(220, 220, 255));
               scale=0;
               sw=(int)(10/divfx);
               while (1+scale+sw<661){
               h.fillRect((1+scale+zerox),0,sw,352);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              

    Thanks,
    I have tried it using
    public void paintComponent(Graphics g){
    drawStuff();
    }in the main body of code and then call upon PaintComponent when I close the settings frame but it makes no difference, I still get the big white box as shown in Q3 - I've tried reading the problem solving section for swing graphics from sun but to no avail.
    Any advice on where paintcomponent should be placed / called?
    Any ideas would be great.
    Thanks,
    John

  • How do I load graphics at boot, to make the initial paint faster?

    I'm running a big application, with many screens (JPanels) on a slow system. The average time for the system to change screens is about 200ms. The first time you visit a screen, the average time to load is 400ms. Every time after that, its about 200ms. All of the screen are on top of each other, with setVisible(false) applied to all but the visible one. The only call made when changing screens is setVisible(false) and setVisible(true) (one to turn the previous screen off, the other to turn the new one on. I'm trying to find a way to get rid of that initial 400ms, and bring it down to 200ms. Is there anyway I can cache the graphics before the page is first visited?

    No, i dont think that is it. I think I have narrowed it down to something very simplistic. Say you extend JPanel, and at the end of your initialization for this panel, you say
    System.out.println(this.getGraphics());
    It will print out "null".
    It will continue to say null, from any point that you call this, until it is visibly painted to the screen. After that it will return something like sun.java2d.SunGraphics2d....etc. Something that basically identifies this Graphics object. What i believe will solve my issue, is figuring out how to get the "getGraphics()" method to return something other than null BEFORE it is initially painted to the screen. Once the Graphics object is instantiated, I believe that will solve the extra time issue when first entering a screen. Using a card layout will still make the graphics object null until it is first painted....or something else initializes it...and that is what I'm trying to figure out.

  • JMF + JWS + Applet

    I'm working in a project with JMF and JWS (maybe Applets).
    My application needs to capture a image from a webcam.
    I know I have to sign my jar files, but my application isn't working at all, cause I can't start my webcam from my application. Always getting a nullPointerException.
    In the Eclipse IDE, the same application works very fine.
    My questions are:
    1. May I have to sign the jmf.jar?
    2. Where may I have to copy them?
    Apreciate any help.

    >
    1. It was already in my plans use JFrame and JWS. Applets is my B plan.>I would demote the plan 'B' to a plan 'C'. Applets are a PITA, and rarely a solution to ..anything.
    >
    2. My jnlp file have all-permissions in security tag.>It was in the wrong place, see below.
    >
    3. I don't get the NoClassDefFoundError. Instead, I got NullPointerException, 'cause my application don't find any webcam. Only in Eclipse IDE Enviroment.>Uh-huh. Not entirely sure of the exact meaning/cause of the NPE yet, but it might be a caching problem.
    <http://forum.java.sun.com/thread.jspa?threadID=5209499>
    Here is a thread where I describe how to change the cahce location, and the advantages of doing so (for testing).
    >
    4. My question is: What do I have to do with jmf.jar and his friends? Signed them too ( I've signed them but it didn't work )? >I am not entirely convinced that the code signing failed. There are still too many variables to determine if the code was ever considered 'trusted'.
    >
    ..Copy them where?>Add the JNLP codebase to the href for a jar, and the jar should be placed/available 'there'. If you can fetch it using the browser using that final URL, it should be fine.
    E.G. the codebase of this JNLP is http://localhost:8080/Capture/, and the href for the first jar is aCapture.jar. So the final URL would be
    http://localhost:8080/Capture/ + aCapture.jar
    ->
    http://localhost:8080/Capture/aCapture.jar
    If the href had been 'lib/aCapture.jar', the final URL would be..
    http://localhost:8080/Capture/lib/aCapture.jar
    Simple, huh?
    >
    5. Something about "vfw:Microsoft WDM Image Capture (Win32):0"?>I do not understand that question.
    >
    6. What is Dukes?>You seem to have figured that out. ;-)
    >
    Next my jnlp file:>- The <security> element was 'out of order', it has been 'put in its place' in the JNLP file below. BTW - are you prompted to 'accept the code from..' (or words to that effect)?
    That would indicate that the plug-in understands this is code that needs all-permissions.
    - The JNLP element's 'spec' attribute refers not to a J2SE version, but to the JNLP specification version. Most apps. will have '1.0', but apps. that use features built into JWS in J2SE 5, might specify '1.5'. (There were no changes to JWS in versions 1.2/1.3/1.4).
    - Are you certain that the jars aCapture.jar, mediaplayer.jar & jmf.jar are the only things on the classpath of the app. when it runs in the IDE? I was almost expecting to see some references to 'nativelib's. Here is an example(2) of another JNLP that includes nativelibs (note that I did not check into it deeply, but some of the things in it appear either wrong, or at the least redundant - only the references to nativelibs are of interest).
    1) The valid JNLP file
    <?xml version="1.0" encoding="utf-8"?>
    <!-- JNLP File for Capture Demo Application -->
    <jnlp
    spec="1.0"
    codebase="http://localhost:8080/Capture/" href="exemplo.jnlp">
    <information>
      <title>Capture Demo Application</title>
      <vendor>DESofts</vendor>
      <homepage href="docs/help.html"/>
      <description>Capture Demo Application</description>
      <description kind="short">
        A demo of the capabilities of the Swing Graphical User Interface.
      </description>
      <icon href="images/icone.jpg"/>
      <icon kind="splash" href="images/icone.jpg"/>
      <offline-allowed/>
      <shortcut online="false">
        <desktop/>
        <menu submenu="My Corporation Apps"/>
      </shortcut>
    </information>
    <security>
      <all-permissions/>
    </security>
    <resources>
      <j2se version="1.4+"/>
      <jar href="aCapture.jar"/>
      <jar href="mediaplayer.jar"/>
      <jar href="jmf.jar"/>
    </resources>
    <application-desc main-class="Capture"/>
    </jnlp> 2) The example JNLP that mentions natives, from
    <http://www.dutchie.net/jmf/example/webstart/launchNative_MP3.jnlp>
    (with minor formatting variations that hopefully do not change its meaning.)
    <?xml version="1.0" encoding="UTF-8"?>
    <jnlp codebase="http://www.dutchie.net/jmf/example/webstart" href="launchNative_MP3.jnlp">
    <information>
      <title>JMF Demo</title>
      <vendor>Dutchie Pty Ltd</vendor>
      <homepage href="http://www.dutchie.net"/>
      <description>The JMF Demo.</description>
      <description kind="short">Demo showing features of JMF</description>
        <description kind="one-line">JMF Demo</description>
        <description kind="tooltip">Click here to launch the JMF Demo</description> 
        <icon href="dutchieIcon.gif"/>
        <icon kind="splash" href="splash.gif"/>
        <offline-allowed/>
    </information>
    <security>
      <all-permissions/>
    </security>
    <resources>
        <j2se version="1.4+"/> 
        <jar href="JMediaDemo.jar" main="true" download="eager"/>  
        <jar href="mp3plugin.jar" download="eager"/>     
    </resources>
    <resources os="Windows" arch="x86">
      <nativelib href="jmf_native_windows.jar"/>
      <jar href="sun_jmf_generic.jar" download="eager"/>
    </resources>
    <resources os="SunOS" arch="sparc">
      <nativelib href="jmf_native_solaris.jar"/>
      <jar href="sun_jmf_generic.jar" download="eager"/>   
    </resources>
    <resources os="Linux">
      <nativelib href="jmf_native_linux.jar"/>
      <jar href="sun_jmf_generic.jar" download="eager"/>   
    </resources>
    <application-desc main-class="org.jmfapi.JMediaDemo"> 
      <argument>jmf</argument>
      <argument>native</argument>
      <argument>sun_mp3_plugin</argument>
      <argument>oggvorbis</argument> 
      <argument>webstart</argument> 
    </application-desc>
    </jnlp>

  • Java must be hardware integrated on standard PC's

    We are working on Java Tech for 10+ years as I see the most disadvantage of Java is now ,
    its still Virtual , for 10+ years of experience I've seen is , always hardware friendly software won the race like
    OpenGL and DirectX on Graphics side.
    Hardware compatible systems forces developers to use them as a standard more.
    If OpenGL was just software layer , all people would do their own Engine.
    But its stopping them to use they use them for best performance.
    And for end users , they are happy because OpenGL hardware friendly and
    that makes OpenGL very fast and make both end user happy.
    Whats the lack of things on Java Tech ?
    Its still Virtual Machine.
    Java should be real machine on PC's !!!
    As i read , AMD LWP will be released for .NET and Java VM
    but in my opinion , it cant help Java for to be faster.
    Java has IO and memory problem so how can these problems can be solved ?
    In my opinion , if you implement simple Gigabyte i-RAM on 1 PC ,
    http://www.gigabyte.com.tw/Products/Storage/Products_Overview.aspx?ProductID=2180
    You will see Java will run very fast startup time and class loads , image loading operation will be very fast !!!
    That means on just IO operations java will be faster.
    Yes but its not solving problem %100 , so ?
    You should implement static caches for Java on PC's instead of making java on Operating System.
    Some people know about UPNP ,
    I've opened JUPNP project on dev.java.net :
    https://jupnp.dev.java.net/
    UPNP is now being used on hardwares of PC's on modems especially!
    But i wished to see JXTA on ADSL and future of modems.
    JXTA would be cool technology having all modems these tech.
    UPHP doesnt have capabilities what JXTA has !
    But it forces developers to use UPNP because all hardware modems have that Technology!
    The most disadvantage of Java Swing Apps is ,
    They all store their Swing Images on HDD ,
    They also should be stored on GPU hardware.
    Yes I've read Java can access on GPU too but i mean all swing images and object must be in seperate static cache of Graphics card so
    when PC startup , they must be loaded on Graphics Card.
    Java must have a classes that accesses,
    MMX , SIMD capabilities of hardwares.
    But they shouldnt be done on JNI !!!
    JNI makes penalty calls , they sould be native instructions.
    You should make new Generation of PC's having
    static java caches like Gigabyte iRam
    same iRam should be on Graphics adapter Swing too...
    Maybe you say it will be expensive PC's but people paying 250$+ for DirectX compatible graphic hardwares!
    think more how much cost iRam on Java/Swing Graphic Adapter or JXTA Compatible ADSL/Cable/?
    If , these technologies will be done , i'm sure within 7 years Java will take place much and much more on markets!
    Send Java and .NET Technologies to hell and as i read your all hardware servers is World's best ,
    if you do same best hardwares for end users it will change destiny of Java/JavaFX.
    Never think virtual , real machines!!!
    PC's really important technology then any other technology to force people accept technologies!
    Dont forget Java needs Fast IO Hardware System now!
    Take care all Sun Group
    Regards,
    Kadir BASOL

    WTF? It's hard enough to get people to download the latest JRE. How many folks do you think will be willing to go out and purchase a new "Java Card" for their PC every two years?

  • Java must be real hardware on PCs !

    We are working on Java Tech for 10+ years as I see the most disadvantage of Java is now ,
    its still Virtual , for 10+ years of experience I've seen is , always hardware friendly software won the race like
    OpenGL and DirectX on Graphics side.
    Hardware compatible systems forces developers to use them as a standard more.
    If OpenGL was just software layer , all people would do their own Engine.
    But its stopping them to use they use them for best performance.
    And for end users , they are happy because OpenGL hardware friendly and
    that makes OpenGL very fast and make both end user happy.
    Whats the lack of things on Java Tech ?
    Its still Virtual Machine.
    Java should be real machine on PC's !!!
    As i read , AMD LWP will be released for .NET and Java VM
    but in my opinion , it cant help Java for to be faster.
    Java has IO and memory problem so how can these problems can be solved ?
    In my opinion , if you implement simple Gigabyte i-RAM on 1 PC ,
    http://www.gigabyte.com.tw/Products/Storage/Products_Overview.aspx?ProductID=2180
    You will see Java will run very fast startup time and class loads , image loading operation will be very fast !!!
    That means on just IO operations java will be faster.
    Yes but its not solving problem %100 , so ?
    You should implement static caches for Java on PC's instead of making java on Operating System.
    Some people know about UPNP ,
    I've opened JUPNP project on dev.java.net :
    https://jupnp.dev.java.net/
    UPNP is now being used on hardwares of PC's on modems especially!
    But i wished to see JXTA on ADSL and future of modems.
    JXTA would be cool technology having all modems these tech.
    UPHP doesnt have capabilities what JXTA has !
    But it forces developers to use UPNP because all hardware modems have that Technology!
    The most disadvantage of Java Swing Apps is ,
    They all store their Swing Images on HDD ,
    They also should be stored on GPU hardware.
    Yes I've read Java can access on GPU too but i mean all swing images and object must be in seperate static cache of Graphics card so
    when PC startup , they must be loaded on Graphics Card.
    Java must have a classes that accesses,
    MMX , SIMD capabilities of hardwares.
    But they shouldnt be done on JNI !!!
    JNI makes penalty calls , they sould be native instructions.
    You should make new Generation of PC's having
    static java caches like Gigabyte iRam
    same iRam should be on Graphics adapter Swing too...
    Maybe you say it will be expensive PC's but people paying 250$+ for DirectX compatible graphic hardwares!
    think more how much cost iRam on Java/Swing Graphic Adapter or JXTA Compatible ADSL/Cable/?
    If , these technologies will be done , i'm sure within 7 years Java will take place much and much more on markets!
    Send Java and .NET Technologies to hell and as i read your all hardware servers is World's best ,
    if you do same best hardwares for end users it will change destiny of Java/JavaFX.
    Never think virtual , real machines!!!
    PC's really important technology then any other technology to force people accept technologies!
    Dont forget Java needs Fast IO Hardware System now!
    Take care all Sun Group
    Regards,
    Kadir BASOL

    WTF? It's hard enough to get people to download the latest JRE. How many folks do you think will be willing to go out and purchase a new "Java Card" for their PC every two years?

  • Runtime error accessing ArrayList

    These 2 classes are basically the classes from the book developing games in java, without the fullscreen stuff. They are supposed to create an animation. They both compile fine but when I run I get an error message, an no animation, paint() is only called once. Here's the error message:
    Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
    at java.util.ArrayList.RangeCheck(ArrayList.java:546)
    at java.util.ArrayList.get(ArrayList.java:321)
    at Animation.getFrame(Animation.java:60)
    at Animation.update(Animation.java:43)
    at AnimationTest1.animationLoop(AnimationTest1.java:58)
    at AnimationTest1.run(AnimationTest1.java:44)
    at AnimationTest1.main(AnimationTest1.java:10)
    I think this means the program is trying to access frame 4 when there is none. Right? I just can't get my brain around this. Any help would be great!
    import java.awt.Image;
    import java.util.ArrayList;
    /*     this class manages a serie of images (frames) and the amount of time to
         display each frame */
    public class Animation {
         private ArrayList frames;
         private int currFrameIndex;
         private long animTime;
         private long totalDuration;
         //creates a new, empty animation, calls start().
         public Animation() {
              frames = new ArrayList();
              totalDuration = 0;
              start();
         //adds an image to the animation, + how long to display the image.
         public synchronized void addFrame(Image image, long duration) {
              totalDuration += duration;
              frames.add(new AnimFrame(image, totalDuration));
         //starts this animation over from the beginning .
         public synchronized void start() {
              animTime = 0;
              currFrameIndex = 0;
         //updates this animations current frame if necessary
         public synchronized void update(long elapsedTime) {
              if (frames.size() >1) {
                   animTime += elapsedTime;
                   if (animTime >= totalDuration) {
                        animTime = animTime % totalDuration;
                        currFrameIndex = 0;
                   while (animTime > getFrame(currFrameIndex).endTime) {
                        currFrameIndex ++;
         //gets the animations current frame. null if none availible.
         public synchronized Image getImage() {
              if (frames.size() == 0) {
                   return null;
              else {
                   return getFrame(currFrameIndex).image;
         private AnimFrame getFrame(int i) {
              return (AnimFrame)frames.get(i);
         private class AnimFrame {
              Image image;
              long endTime;
              public AnimFrame(Image image, long endtime) {
                   this.image = image;
                   this.endTime = endTime;
    import java.awt.*;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    public class AnimationTest1 {
         public static void main (String args[]) {          
              AnimationTest1 test = new AnimationTest1();
              test.run();
         private static final long DEMO_TIME = 5000;
         private JFrame frame;
         private Animation anim;
         public void loadImages() {
              //load images
              Image player1 = loadImage("gif1.png");
              Image player2 = loadImage("gif2.png");
              Image player3 = loadImage("gif3.png");
              //create animation
              anim = new Animation();
              anim.addFrame(player1, 200);
              anim.addFrame(player2, 200);
              anim.addFrame(player3, 200);
              anim.addFrame(player2, 200);
         //loads image with ImageIcon
         private Image loadImage(String filename) {
              return new ImageIcon(filename).getImage();
         public void run() {
              try {
                   frame = new JFrame();
                   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   frame.setSize(300, 300);
                   frame.setVisible(true);
                   loadImages();
                   animationLoop();
              finally {
         public void animationLoop() {
              long startTime = System.currentTimeMillis();
              long currTime = startTime;
              while (currTime - startTime < DEMO_TIME) {
                   long elapsedTime = System.currentTimeMillis() - currTime;
                   currTime += elapsedTime;
                   anim.update(elapsedTime);
                   //getContentpane.getgraphics??!!
                   Graphics g = frame.getGraphics();
                   draw(g);
                   g.dispose();
                   try {
                        Thread.sleep(20);
                   catch (InterruptedException ex) {}
         //draw the animation
         public void draw(Graphics g) {
              g.setColor(Color.white);
              g.fillRect(0, 0, 300, 300);          
              g.drawImage(anim.getImage(), 0, 0, null);
    }

    106498II wrote:
    i changed it to read:
    while (animTime > getFrame(currFrameIndex).endTime) {
                        currFrameIndex ++;
                        if (currFrameIndex >3) {
                             currFrameIndex = 0;
                        }this gets rid of the error but still no animation. Perhaps its something to do with that I draw directly on the JFrame?On the JFrame? Better to draw in a JPanel or JComponent. Also, perhaps you're trying to animate on the EDT in which case you get the beginning picture, and the end picture but usually you get nothing in between. Are you using a non-EDT thread or a Swing Timer?
    Addendum: yeah it looks like you're trying to put the EDT (event dispatch thread -- the main thread that runs Swing) to sleep here. Please don't do this. Also you're trying to draw outside of a paint or paintComponent method.
    Solution: Run don't walk to the Sun java2D and Swing graphics tutorials and read and study them.
    Edited by: petes1234 on Dec 11, 2007 7:21 PM

  • Floating boxes applet with drag events need click event

    I Have an applet cobbled from the net & modified. Is works but needs one major event added. It draws "Graphics.drawline" boxes with a text "String" inside each box ( the text string represents an URL location). These "boxes" are objects which are "draggable to other locations on canvas & therefore can be independently positioned by user. Each box redraws itself periodically to a slightly different screen location & becomes stationary after a 5 or 6 seconds. The point is, all of this "drag & mobility" behavior must remain intact & is not part of the "problem task".
    Task: Need to have an "event" behavior added in one of two ways ( or a 3rd way if there is another ) whichever is quickest/ easiest. "Clickable mouse events" must be added to each box. ( boxes are built in a loop so adding to one will add to other locations & create as many "buttons" as there are boxes) . At each box's location, clicking one box should be an event which fires & clicking a different box should be a separate event which fires. Separate , so that URL location can be "hotlinked" to each box. That URL is currently displayed in the boxes (visible when running applet).
    1st possible solution: Exchange these "boxes" which appear on canvas into clickable event "Graph panel.buttons" ( for example or some other clickable object) which maintains existing "drag" behavior of boxes. These buttons must each have "clickability" with mouse events to enable placing "getAppletContext. showDocument()" code with these events ( e.g., "hotlinked" to http locations).
    or
    2nd possible solution:. The drawstring boxes are currently dead string text with no event model other than the "drag" feature associated with each box. Must add an additional mouse event behavior to existing boxes so they are "clickable" ( or text inside is clickable) and can then execute "showDocument()" URL when clicked independently.
    Maybe there is a #3. I don't know what that would be. Open to try anything without losing the drag & placement mobility of existing boxes.
    These "boxes" could be images, or event buttons - doesnt matter.
    Not sure if #2 is possible & have not been able to accomplish #1. Must stay within existing AWT framework so IE browsers can run it natively ( which of course IE cannot run Swing graphics unless a Sun plugin loaded ).
    Applet is a single file ( creating 4 classes).
    html file (which invokes it) passes a string param which is broken into above noted URL strings in each box.
    Running this applet, you see a "button" event ( at base of canvas labeled "NewUrl" ) which pops up an url location when clicked ( using "showdocument"). This button is not attached to locations or text of each box object ( which is the "task" to accomplish) . The button does represent the kind of event behavior which each "box" should have when task is achieved. So the box can be exchanged with buttons or the boxes can be imbued with events to hyperlink like a button.
    In spirit of solution #1, here is the bonehead attempt I tried which did not work: copied entire "if" block of logic from the button event (sited in preceding paragraph) into region of code which builds boxes ( "for" loop of "drawstring" method).
    "g.drawString(doit, x - (w-10)/2, (y - (h-4)/2) + fm.getAscent());"
    I copied all the "if" block of logic for button creation into the area immediately after the above line ( for loop which builds the boxes). Hoping that I could create buttons with events, along with all the boxes (which are getting created using "drawstring" above in a "for" loop). These "buttons" must also have positioning info of each box to appear in different locations on the canvas. Positioning data is not in that "if" block of code but it would have been a start to get the multiple buttons created ( even if all drawn in one spot). The "if" code block I've provieded for an example begins with the line:
    " if ("NewUrl".equals(arg)) { "
    and ends with with lines:
    " return true; "
    " } " //< -- end of above if block
    This full "if" block can be seen in the listing below:
    This "if" block creates the "NewUrl" button. Of course, I got a bunch of errors when I tried to copy this block to the above location:
    variable: "arg" "not found in class GraphPanel".
    methods: "getcodebase, showstatus, getappletcontext()"
    "not found in class GraphPanel".
    ----------- The applet code in total follows next
    Here are both the java & htm complete source.
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.*;
    import java.util.*;
    import java.awt.*;
    import java.applet.Applet;
    import java.applet.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.*;
    class Node {
    double x;
    double y;
    double dx;
    double dy;
    boolean fixed;
    String lbl;
    class Edge {
    int from;
    int to;
    double len;
    } // eEdgeCla
    class GraphPanel extends Panel implements Runnable {
    Box box;
    int nnodes;
    Node nodes[] = new Node[100];
    int nedges;
    Edge edges[] = new Edge[200];
    Thread relaxer;
    boolean showit;
    boolean random;
    GraphPanel(Box box) {
    this.box = box;
    } //ebox
    int findNode(String lbl) {
    for (int i = 0 ; i < nnodes ; i++) {
    if (nodes.lbl.equals(lbl)) {
    return i;
    return addNode(lbl);
    int addNode(String lbl) {
    Node n = new Node();
    n.x = 10 + 380*Math.random();
    n.y = 10 + 380*Math.random();
    n.lbl = lbl;
    nodes[nnodes] = n;
    return nnodes++;
    void addEdge(String from, String to, int len) {
    Edge e = new Edge();
    e.from = findNode(from);
    e.to = findNode(to);
    e.len = len;
    edges[nedges++] = e;
    public void run() {
    int i3=0;
    while (true) {
    relax();
    if (random && (Math.random() < 0.03)) {
    Node n = nodes[(int) (1 * nnodes) ]; // no
    if (!n.fixed) {
    n.x += (100*0.02) - 50;
    n.y += (100*0.02) - 50; //
    try {
    Thread.sleep(4000);
    } catch (InterruptedException e) {
    break;
    i3++;
    } //ew
    } // epublrun()
    synchronized void relax() {
    for (int i = 0 ; i < nedges ; i++) {
    Edge e = edges;
    double vx = nodes[e.to].x - nodes[e.from].x;
    double vy = nodes[e.to].y - nodes[e.from].y;
    double len = Math.sqrt(vx * vx + vy * vy);
    double f = (edges.len - len) / (len * 3) ;
    double dx = f * vx;
    double dy = f * vy;
    nodes[e.to].dx += dx;
    nodes[e.to].dy += dy;
    nodes[e.from].dx += -dx;
    nodes[e.from].dy += -dy;
    } //efo
    for (int i = 0 ; i < nnodes ; i++) {
    Node n1 = nodes;
    double dx = 0;
    double dy = 0;
    for (int j = 0 ; j < nnodes ; j++) {
    if (i == j) {
    continue;
    Node n2 = nodes[j];
    double vx = n1.x - n2.x;
    double vy = n1.y - n2.y;
    double len = vx * vx + vy * vy;
    if (len == 0) {
    dx += 0.02;
    dy += 0.02;
    } else if (len < 100*100) {
    dx += vx / len;
    dy += vy / len;
    } //ef3a
    double dlen = dx * dx + dy * dy;
    if (dlen > 0) {
    dlen = Math.sqrt(dlen) / 2;
    n1.dx += dx / dlen;
    n1.dy += dy / dlen;
    } //ef3
    Dimension d = size();
    // f4
    for (int i = 0 ; i < nnodes ; i++) {
    Node n = nodes;
    if (!n.fixed) {
    n.x += Math.max(-5, Math.min(5, n.dx));
    n.y += Math.max(-5, Math.min(5, n.dy));
    if (n.x < 0) {
    n.x = 0;
    } else if (n.x > d.width) {
    n.x = d.width;
    if (n.y < 0) {
    n.y = 0;
    } else if (n.y > d.height) {
    n.y = d.height;
    n.dx /= 2;
    n.dy /= 2;
    repaint();
    Node pick;
    boolean pickfixed;
    Image offscreen;
    Dimension offscreensize;
    Graphics offgraphics;
    final Color fixedColor = Color.green;
    final Color selectColor = Color.gray;
    final Color edgeColor = Color.black;
    final Color nodeColor = new Color(200, 90, 50);
    final Color showitColor = Color.gray;
    final Color arcColor1 = Color.black;
    final Color arcColor2 = Color.orange;
    final Color arcColor3 = Color.blue;
    public void paintNode( Graphics g, Node n, FontMetrics fm) {
    int x = (int)n.x;
    int y = (int)n.y;
    g.setColor((n == pick) ? selectColor : (n.fixed ? fixedColor : nodeColor));
    int w = fm.stringWidth(n.lbl) + 10;
    int h = fm.getHeight() + 4;
    g.fillRect(x - w/2, y - h / 2, w, h);
    g.setColor(Color.black);
    g.drawRect(x - w/2, y - h / 2, w-1, h-1);
    String doit = n.lbl.replace('x','/');
    g.drawString(doit, x - (w-10)/2, (y - (h-4)/2) + fm.getAscent());
    } // epa
    public synchronized void update(Graphics g) {
    Dimension d = size();
    if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) {
    offscreen = createImage(d.width, d.height);
    offscreensize = d;
    offgraphics = offscreen.getGraphics();
    offgraphics.setFont(getFont());
    offgraphics.setColor(getBackground());
    offgraphics.fillRect(0, 0, d.width, d.height);
    for (int i = 0 ; i < nedges ; i++) {
    Edge e = edges;
    int x1 = (int)nodes[e.from].x;
    int y1 = (int)nodes[e.from].y;
    int x2 = (int)nodes[e.to].x;
    int y2 = (int)nodes[e.to].y;
    int len = (int)Math.abs(Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) - e.len);
    offgraphics.setColor((len < 10) ? arcColor1 : (len < 20 ? arcColor2 : arcColor3)) ;
    offgraphics.drawLine(x1, y1, x2, y2);
    if (showit) {
    String lbl = String.valueOf(len);
    offgraphics.setColor(showitColor);
    offgraphics.drawString("href= http://localhost:"+lbl, x1 + (x2-x1)/2, y1 + (y2-y1)/2);
    offgraphics.setColor(edgeColor);
    } //ef5
    FontMetrics fm = offgraphics.getFontMetrics();
    for (int i = 0 ; i < nnodes ; i++) {
    paintNode( offgraphics, nodes, fm); //or
    g.drawImage(offscreen, 0, 0, null);
    public synchronized boolean mouseDown(Event evt, int x, int y) {
    double bestdist = Double.MAX_VALUE;
    for (int i = 0 ; i < nnodes ; i++) {
    Node n = nodes;
    double dist = (n.x - x) * (n.x - x) + (n.y - y) * (n.y - y);
    if (dist < bestdist) {
    pick = n;
    bestdist = dist;
    pickfixed = pick.fixed;
    pick.fixed = true;
    pick.x = x;
    pick.y = y;
    repaint();
    return true;
    public synchronized boolean mouseDrag(Event evt, int x, int y) {
    pick.x = x;
    pick.y = y;
    repaint();
    return true;
    } //e-pubsyncmousedrag
    public synchronized boolean mouseUp(Event evt, int x, int y) {
    pick.x = x;
    pick.y = y;
    pick.fixed = pickfixed;
    pick = null;
    repaint();
    return true;
    public void start() {
    relaxer = new Thread(this);
    relaxer.start();
    public void stop() {
    relaxer.stop();
    public class Box extends Applet {
    GraphPanel panel;
    public void init() {
    setLayout(new BorderLayout());
    panel = new GraphPanel(this);
    add("Center", panel);
    Panel p = new Panel();
    add("South", p);
    p.add(new Button("Reposition"));
    p.add(new Button("NewUrl"));
    p.add(new Checkbox("Showit"));
    String edges = getParameter("edges"); // putinli
    for (StringTokenizer t = new StringTokenizer(edges, ",") ; t.hasMoreTokens() ; ) {
    String str = t.nextToken();
    int i = str.indexOf('-');
    if (i > 0) { int len = 50;
    int j = str.indexOf('/');
    if (j > 0) {
    len = Integer.valueOf(str.substring(j+1)).intValue();
    str = str.substring(0, j);
    panel.addEdge(str.substring(0,i), str.substring(i+1), len);
    } //ef8
    Dimension d = size();
    String center = getParameter("center");
    if (center != null){
    Node n = panel.nodes[panel.findNode(center)];
    n.x = d.width / 2;
    n.y = d.height / 2;
    n.fixed = true;
    } // eif
    } // ep
    public void start() {
    panel.start();
    public void stop() {
    panel.stop();
    public boolean action(Event evt, Object arg) {
    if (arg instanceof Boolean) {
    if (((Checkbox)evt.target).getLabel().equals("Showit")) {
    panel.showit = ((Boolean)arg).booleanValue();
    }// e-
    else {
    panel.random = ((Boolean)arg).booleanValue();
    return true;
    } // e-if instof bool
    if ("Reposition".equals(arg)) {
    Dimension d = size();
    for (int i = 0 ; i < panel.nnodes ; i++) {
    Node n = panel.nodes;
    if (!n.fixed) {
    n.x = 10 + (d.width-20)*Math.random();
    n.y = 10 + (d.height-20)*Math.random();
    } //ei
    } //ef9
    return true;
    } //eif scram
    if ("NewUrl".equals(arg)) {
    Dimension d = size();
    URL url = getCodeBase();
    try {
    getAppletContext().showDocument( new URL(url+"main.htm"), "_blank" );
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) { }
    } catch(MalformedURLException e) {
    showStatus("814 URL not found");
    for (int i = 0 ; i < panel.nnodes ; i++) {
    Node n = panel.nodes;
    if (!n.fixed) {
    n.x += (80*0.02) - 40;
    n.y += (80*0.02) - 40;
    return true;
    } //ei
    return false;
    -----------------------htm file to launch------------------------------
    <html>
    <head>
    <title>R
    </title>
    </head>
    <body>
    <h3>
    <center>
    R
    </center>
    </h3>
    I
    <b>
    </b>
    <table border = 1>
    <td>De<td>Test List<tr>
    <td>N <td><tr>
    <td>N <td><tr>
    </table>
    <b>view </b>
    <applet code="Box.class" CODEBASE=. width=1000 height=600
    ALT="Test ">
    <param name=edges value="http:xxabc.htm-http:xxnet.htm,http:xxthis.htm-http:xx.comet.htm,http:xxnewsighting.htm-http:xxstar.htm,http:xxmoon.htm-http:xxNeptune.htm">
    <hr>
    </applet>
    </b>
    <p>
    <table border = 1>
    <tr>
    <tr>
    </table>
    </html>
    </body>
    instructions to compile :
    0 : The discussion becomes easy to follow after 1st compiling
    & viewing the applet.
    1. : cut out applet code.
    2. : the post somehow deleted all references to "" <--- HERE
    see, the data has been deleted again as I preview this post.
    ( that "" should contain an "i" array increment argument:
    "open square bracket" "i" "close square bracket" ) array
    so "javac Box.java" will get 10 errors. These "[" "i" "]"
    array args must be replaced to compile the code.
    3. : All array variables inside the 10 "for" loops ( the bare words
    "edges" and "nodes" ) without array increment "i" should
    read "edges" "[" "i" "]" & "nodes" "[" "i" "]".
    The 10 location lines are approx:
    line #65, #129, #136, #149, #195, #283, #311, #331, #477, #522
    4. : These 10 edits reqresent a missing "i" to all 10 for loop arrays.
    for eddges & nodes. fix this & javac Box.java" will get
    4 class files.
    5. : cut "Box.htm" from post & do "appletviewer Box.htm"
    or put in an apache "htdoc" or tomcat "servlet" http delivered
    directory & call "http://localhost/Box.htm.
    6. : of course, selecting the event button "NewUrl" will not
    work in appletviewer but will work in an http web location.
    7. : post your questions to problem or fixes to problem as I'm
    monitoring closely. TIA.

    Thanks for code post tip to fix array deletion problem.
    Here is code reposted using delimiters with will
    compile straight out of cut/paste.import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.*;
    import java.util.*;
    import java.awt.*;
    import java.applet.Applet;
    import java.applet.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.*;
    class Node {
    double x;
    double y;
    double dx;
    double dy;
    boolean fixed;
    String lbl;
    class Edge {
    int from;
    int to;
    double len;
    } // eEdgeCla
    class GraphPanel extends Panel implements Runnable {
    Box box;
    int nnodes;
    Node nodes[] = new Node[100];
    int nedges;
    Edge edges[] = new Edge[200];
    Thread relaxer;
    boolean showit;
    boolean random;
    GraphPanel(Box box) {
    this.box = box;
    } //ebox
    int findNode(String lbl) {
    for (int i = 0 ; i < nnodes ; i++) {
    //if (nodes.lbl.equals(lbl)) {
    if (nodes.lbl.equals(lbl)) {
    return i;
    return addNode(lbl);
    int addNode(String lbl) {
    Node n = new Node();
    n.x = 10 + 380*Math.random();
    n.y = 10 + 380*Math.random();
    n.lbl = lbl;
    nodes[nnodes] = n;
    return nnodes++;
    void addEdge(String from, String to, int len) {
    Edge e = new Edge();
    e.from = findNode(from);
    e.to = findNode(to);
    e.len = len;
    edges[nedges++] = e;
    public void run() {
    int i3=0;
    while (true) {
    relax();
    if (random && (Math.random() < 0.03)) {
    Node n = nodes[(int) (1 * nnodes) ]; // no
    if (!n.fixed) {
    n.x += (100*0.02) - 50;
    n.y += (100*0.02) - 50; //
    try {
    Thread.sleep(4000);
    } catch (InterruptedException e) {
    break;
    i3++;
    } //ew
    } // epublrun()
    synchronized void relax() {
    for (int i = 0 ; i < nedges ; i++) {
    //Edge e = edges;
    Edge e = edges[i];
    double vx = nodes[e.to].x - nodes[e.from].x;
    double vy = nodes[e.to].y - nodes[e.from].y;
    double len = Math.sqrt(vx * vx + vy * vy);
    //double f = (edges.len - len) / (len * 3) ;
    double f = (edges[i].len - len) / (len * 3) ;
    double dx = f * vx;
    double dy = f * vy;
    nodes[e.to].dx += dx;
    nodes[e.to].dy += dy;
    nodes[e.from].dx += -dx;
    nodes[e.from].dy += -dy;
    } //efo
    for (int i = 0 ; i < nnodes ; i++) {
    //Node n1 = nodes[i];
    Node n1 = nodes[i];
    double dx = 0;
    double dy = 0;
    for (int j = 0 ; j < nnodes ; j++) {
    if (i == j) {
    continue;
    Node n2 = nodes[j];
    double vx = n1.x - n2.x;
    double vy = n1.y - n2.y;
    double len = vx * vx + vy * vy;
    if (len == 0) {
    dx += 0.02;
    dy += 0.02;
    } else if (len < 100*100) {
    dx += vx / len;
    dy += vy / len;
    } //ef3a
    double dlen = dx * dx + dy * dy;
    if (dlen > 0) {
    dlen = Math.sqrt(dlen) / 2;
    n1.dx += dx / dlen;
    n1.dy += dy / dlen;
    } //ef3
    Dimension d = size();
    // f4
    for (int i = 0 ; i < nnodes ; i++) {
    //Node n = nodes;
    Node n = nodes[i];
    if (!n.fixed) {
    n.x += Math.max(-5, Math.min(5, n.dx));
    n.y += Math.max(-5, Math.min(5, n.dy));
    if (n.x < 0) {
    n.x = 0;
    } else if (n.x > d.width) {
    n.x = d.width;
    if (n.y < 0) {
    n.y = 0;
    } else if (n.y > d.height) {
    n.y = d.height;
    n.dx /= 2;
    n.dy /= 2;
    repaint();
    Node pick;
    boolean pickfixed;
    Image offscreen;
    Dimension offscreensize;
    Graphics offgraphics;
    final Color fixedColor = Color.green;
    final Color selectColor = Color.gray;
    final Color edgeColor = Color.black;
    final Color nodeColor = new Color(200, 90, 50);
    final Color showitColor = Color.gray;
    final Color arcColor1 = Color.black;
    final Color arcColor2 = Color.orange;
    final Color arcColor3 = Color.blue;
    public void paintNode( Graphics g, Node n, FontMetrics fm) {
    int x = (int)n.x;
    int y = (int)n.y;
    g.setColor((n == pick) ? selectColor : (n.fixed ? fixedColor : nodeColor));
    int w = fm.stringWidth(n.lbl) + 10;
    int h = fm.getHeight() + 4;
    g.fillRect(x - w/2, y - h / 2, w, h);
    g.setColor(Color.black);
    g.drawRect(x - w/2, y - h / 2, w-1, h-1);
    String doit = n.lbl.replace('x','/');
    g.drawString(doit, x - (w-10)/2, (y - (h-4)/2) + fm.getAscent());
    } // epa
    public synchronized void update(Graphics g) {
    Dimension d = size();
    if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) {
    offscreen = createImage(d.width, d.height);
    offscreensize = d;
    offgraphics = offscreen.getGraphics();
    offgraphics.setFont(getFont());
    offgraphics.setColor(getBackground());
    offgraphics.fillRect(0, 0, d.width, d.height);
    for (int i = 0 ; i < nedges ; i++) {
    //Edge e = edges;
    Edge e = edges[i];
    int x1 = (int)nodes[e.from].x;
    int y1 = (int)nodes[e.from].y;
    int x2 = (int)nodes[e.to].x;
    int y2 = (int)nodes[e.to].y;
    int len = (int)Math.abs(Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) - e.len);
    offgraphics.setColor((len < 10) ? arcColor1 : (len < 20 ? arcColor2 : arcColor3)) ;
    offgraphics.drawLine(x1, y1, x2, y2);
    if (showit) {
    String lbl = String.valueOf(len);
    offgraphics.setColor(showitColor);
    offgraphics.drawString("href= http://localhost:"+lbl, x1 + (x2-x1)/2, y1 + (y2-y1)/2);
    offgraphics.setColor(edgeColor);
    } //ef5
    FontMetrics fm = offgraphics.getFontMetrics();
    for (int i = 0 ; i < nnodes ; i++) {
    //paintNode( offgraphics, nodes, fm); //or
    paintNode( offgraphics, nodes[i], fm); //or
    g.drawImage(offscreen, 0, 0, null);
    public synchronized boolean mouseDown(Event evt, int x, int y) {
    double bestdist = Double.MAX_VALUE;
    for (int i = 0 ; i < nnodes ; i++) {
    //Node n = nodes;
    Node n = nodes[i];
    double dist = (n.x - x) * (n.x - x) + (n.y - y) * (n.y - y);
    if (dist < bestdist) {
    pick = n;
    bestdist = dist;
    pickfixed = pick.fixed;
    pick.fixed = true;
    pick.x = x;
    pick.y = y;
    repaint();
    return true;
    public synchronized boolean mouseDrag(Event evt, int x, int y) {
    pick.x = x;
    pick.y = y;
    repaint();
    return true;
    } //e-pubsyncmousedrag
    public synchronized boolean mouseUp(Event evt, int x, int y) {
    pick.x = x;
    pick.y = y;
    pick.fixed = pickfixed;
    pick = null;
    repaint();
    return true;
    public void start() {
    relaxer = new Thread(this);
    relaxer.start();
    public void stop() {
    relaxer.stop();
    public class Box extends Applet {
    GraphPanel panel;
    public void init() {
    setLayout(new BorderLayout());
    panel = new GraphPanel(this);
    add("Center", panel);
    Panel p = new Panel();
    add("South", p);
    p.add(new Button("Reposition"));
    p.add(new Button("NewUrl"));
    p.add(new Checkbox("Showit"));
    String edges = getParameter("edges"); // putinli
    for (StringTokenizer t = new StringTokenizer(edges, ",") ; t.hasMoreTokens() ; ) {
    String str = t.nextToken();
    int i = str.indexOf('-');
    if (i > 0) { int len = 50;
    int j = str.indexOf('/');
    if (j > 0) {
    len = Integer.valueOf(str.substring(j+1)).intValue();
    str = str.substring(0, j);
    panel.addEdge(str.substring(0,i), str.substring(i+1), len);
    } //ef8
    Dimension d = size();
    String center = getParameter("center");
    if (center != null){
    Node n = panel.nodes[panel.findNode(center)];
    n.x = d.width / 2;
    n.y = d.height / 2;
    n.fixed = true;
    } // eif
    } // ep
    public void start() {
    panel.start();
    public void stop() {
    panel.stop();
    public boolean action(Event evt, Object arg) {
    if (arg instanceof Boolean) {
    if (((Checkbox)evt.target).getLabel().equals("Showit")) {
    panel.showit = ((Boolean)arg).booleanValue();
    }// e-
    else {
    panel.random = ((Boolean)arg).booleanValue();
    return true;
    } // e-if instof bool
    if ("Reposition".equals(arg)) {
    Dimension d = size();
    for (int i = 0 ; i < panel.nnodes ; i++) {
    //Node n = panel.nodes;
    Node n = panel.nodes[i];
    if (!n.fixed) {
    n.x = 10 + (d.width-20)*Math.random();
    n.y = 10 + (d.height-20)*Math.random();
    } //ei
    } //ef9
    return true;
    } //eif scram
    if ("NewUrl".equals(arg)) {
    Dimension d = size();
    URL url = getCodeBase();
    try {
    getAppletContext().showDocument( new URL(url+"main.htm"), "_blank" );
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) { }
    } catch(MalformedURLException e) {
    showStatus("814 URL not found");
    for (int i = 0 ; i < panel.nnodes ; i++) {
    //Node n = panel.nodes;
    Node n = panel.nodes[i];
    if (!n.fixed) {
    n.x += (80*0.02) - 40;
    n.y += (80*0.02) - 40;
    return true;
    } //ei
    return false;

  • Floating "boxes" applet with drag events need ckick events

    I Have an applet cobbled from the net & modified. Is works but needs one major event added. It draws "Graphics.drawline" boxes with a text "String" inside each box ( the text string represents an URL location). These "boxes" are objects which are "draggable to other locations on canvas & therefore can be independently positioned by user. Each box redraws itself periodically to a slightly different screen location & becomes stationary after a 5 or 6 seconds. The point is, all of this "drag & mobility" behavior must remain intact & is not part of the "problem task".
    Task: Need to have an "event" behavior added in one of two ways ( or a 3rd way if there is another ) whichever is quickest/ easiest. "Clickable mouse events" must be added to each box. ( boxes are built in a loop so adding to one will add to other locations & create as many "buttons" as there are boxes) . At each box's location, clicking one box should be an event which fires & clicking a different box should be a separate event which fires. Separate , so that URL location can be "hotlinked" to each box. That URL is currently displayed in the boxes (visible when running applet).
    1st possible solution: Exchange these "boxes" which appear on canvas into clickable event "Graph panel.buttons" ( for example or some other clickable object) which maintains existing "drag" behavior of boxes. These buttons must each have "clickability" with mouse events to enable placing "getAppletContext. showDocument()" code with these events ( e.g., "hotlinked" to http locations).
    or
    2nd possible solution:. The drawstring boxes are currently dead string text with no event model other than the "drag" feature associated with each box. Must add an additional mouse event behavior to existing boxes so they are "clickable" ( or text inside is clickable) and can then execute "showDocument()" URL when clicked independently.
    Maybe there is a #3. I don't know what that would be. Open to try anything without losing the drag & placement mobility of existing boxes.
    These "boxes" could be images, or event buttons - doesnt matter.
    Not sure if #2 is possible & have not been able to accomplish #1. Must stay within existing AWT framework so IE browsers can run it natively ( which of course IE cannot run Swing graphics unless a Sun plugin loaded ).
    Applet is a single file ( creating 4 classes).
    html file (which invokes it) passes a string param which is broken into above noted URL strings in each box.
    Running this applet, you see a "button" event ( at base of canvas labeled "NewUrl" ) which pops up an url location when clicked ( using "showdocument"). This button is not attached to locations or text of each box object ( which is the "task" to accomplish) . The button does represent the kind of event behavior which each "box" should have when task is achieved. So the box can be exchanged with buttons or the boxes can be imbued with events to hyperlink like a button.
    In spirit of solution #1, here is the bonehead attempt I tried which did not work: copied entire "if" block of logic from the button event (sited in preceding paragraph) into region of code which builds boxes ( "for" loop of "drawstring" method).
    "g.drawString(doit, x - (w-10)/2, (y - (h-4)/2) + fm.getAscent());"
    I copied all the "if" block of logic for button creation into the area immediately after the above line ( for loop which builds the boxes). Hoping that I could create buttons with events, along with all the boxes (which are getting created using "drawstring" above in a "for" loop). These "buttons" must also have positioning info of each box to appear in different locations on the canvas. Positioning data is not in that "if" block of code but it would have been a start to get the multiple buttons created ( even if all drawn in one spot). The "if" code block I've provieded for an example begins with the line:
    " if ("NewUrl".equals(arg)) { "
    and ends with with lines:
    " return true; "
    " } " //< -- end of above if block
    This full "if" block can be seen in the listing below:
    This "if" block creates the "NewUrl" button. Of course, I got a bunch of errors when I tried to copy this block to the above location:
    variable: "arg" "not found in class GraphPanel".
    methods: "getcodebase, showstatus, getappletcontext()"
    "not found in class GraphPanel".
    ----------- The applet code in total follows next
    Here are both the java & htm complete source.
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.*;
    import java.util.*;
    import java.awt.*;
    import java.applet.Applet;
    import java.applet.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.*;
    class Node {
    double x;
    double y;
    double dx;
    double dy;
    boolean fixed;
    String lbl;
    class Edge {
    int from;
    int to;
    double len;
    } // eEdgeCla
    class GraphPanel extends Panel implements Runnable {
    Box box;
    int nnodes;
    Node nodes[] = new Node[100];
    int nedges;
    Edge edges[] = new Edge[200];
    Thread relaxer;
    boolean showit;
    boolean random;
    GraphPanel(Box box) {
    this.box = box;
    } //ebox
    int findNode(String lbl) {
    for (int i = 0 ; i < nnodes ; i++) {
    if (nodes.lbl.equals(lbl)) {
    return i;
    return addNode(lbl);
    int addNode(String lbl) {
    Node n = new Node();
    n.x = 10 + 380*Math.random();
    n.y = 10 + 380*Math.random();
    n.lbl = lbl;
    nodes[nnodes] = n;
    return nnodes++;
    void addEdge(String from, String to, int len) {
    Edge e = new Edge();
    e.from = findNode(from);
    e.to = findNode(to);
    e.len = len;
    edges[nedges++] = e;
    public void run() {
    int i3=0;
    while (true) {
    relax();
    if (random && (Math.random() < 0.03)) {
    Node n = nodes[(int) (1 * nnodes) ]; // no
    if (!n.fixed) {
    n.x += (100*0.02) - 50;
    n.y += (100*0.02) - 50; //
    try {
    Thread.sleep(4000);
    } catch (InterruptedException e) {
    break;
    i3++;
    } //ew
    } // epublrun()
    synchronized void relax() {
    for (int i = 0 ; i < nedges ; i++) {
    Edge e = edges;
    double vx = nodes[e.to].x - nodes[e.from].x;
    double vy = nodes[e.to].y - nodes[e.from].y;
    double len = Math.sqrt(vx * vx + vy * vy);
    double f = (edges.len - len) / (len * 3) ;
    double dx = f * vx;
    double dy = f * vy;
    nodes[e.to].dx += dx;
    nodes[e.to].dy += dy;
    nodes[e.from].dx += -dx;
    nodes[e.from].dy += -dy;
    } //efo
    for (int i = 0 ; i < nnodes ; i++) {
    Node n1 = nodes;
    double dx = 0;
    double dy = 0;
    for (int j = 0 ; j < nnodes ; j++) {
    if (i == j) {
    continue;
    Node n2 = nodes[j];
    double vx = n1.x - n2.x;
    double vy = n1.y - n2.y;
    double len = vx * vx + vy * vy;
    if (len == 0) {
    dx += 0.02;
    dy += 0.02;
    } else if (len < 100*100) {
    dx += vx / len;
    dy += vy / len;
    } //ef3a
    double dlen = dx * dx + dy * dy;
    if (dlen > 0) {
    dlen = Math.sqrt(dlen) / 2;
    n1.dx += dx / dlen;
    n1.dy += dy / dlen;
    } //ef3
    Dimension d = size();
    // f4
    for (int i = 0 ; i < nnodes ; i++) {
    Node n = nodes;
    if (!n.fixed) {
    n.x += Math.max(-5, Math.min(5, n.dx));
    n.y += Math.max(-5, Math.min(5, n.dy));
    if (n.x < 0) {
    n.x = 0;
    } else if (n.x > d.width) {
    n.x = d.width;
    if (n.y < 0) {
    n.y = 0;
    } else if (n.y > d.height) {
    n.y = d.height;
    n.dx /= 2;
    n.dy /= 2;
    repaint();
    Node pick;
    boolean pickfixed;
    Image offscreen;
    Dimension offscreensize;
    Graphics offgraphics;
    final Color fixedColor = Color.green;
    final Color selectColor = Color.gray;
    final Color edgeColor = Color.black;
    final Color nodeColor = new Color(200, 90, 50);
    final Color showitColor = Color.gray;
    final Color arcColor1 = Color.black;
    final Color arcColor2 = Color.orange;
    final Color arcColor3 = Color.blue;
    public void paintNode( Graphics g, Node n, FontMetrics fm) {
    int x = (int)n.x;
    int y = (int)n.y;
    g.setColor((n == pick) ? selectColor : (n.fixed ? fixedColor : nodeColor));
    int w = fm.stringWidth(n.lbl) + 10;
    int h = fm.getHeight() + 4;
    g.fillRect(x - w/2, y - h / 2, w, h);
    g.setColor(Color.black);
    g.drawRect(x - w/2, y - h / 2, w-1, h-1);
    String doit = n.lbl.replace('x','/');
    g.drawString(doit, x - (w-10)/2, (y - (h-4)/2) + fm.getAscent());
    } // epa
    public synchronized void update(Graphics g) {
    Dimension d = size();
    if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) {
    offscreen = createImage(d.width, d.height);
    offscreensize = d;
    offgraphics = offscreen.getGraphics();
    offgraphics.setFont(getFont());
    offgraphics.setColor(getBackground());
    offgraphics.fillRect(0, 0, d.width, d.height);
    for (int i = 0 ; i < nedges ; i++) {
    Edge e = edges;
    int x1 = (int)nodes[e.from].x;
    int y1 = (int)nodes[e.from].y;
    int x2 = (int)nodes[e.to].x;
    int y2 = (int)nodes[e.to].y;
    int len = (int)Math.abs(Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) - e.len);
    offgraphics.setColor((len < 10) ? arcColor1 : (len < 20 ? arcColor2 : arcColor3)) ;
    offgraphics.drawLine(x1, y1, x2, y2);
    if (showit) {
    String lbl = String.valueOf(len);
    offgraphics.setColor(showitColor);
    offgraphics.drawString("href= http://localhost:"+lbl, x1 + (x2-x1)/2, y1 + (y2-y1)/2);
    offgraphics.setColor(edgeColor);
    } //ef5
    FontMetrics fm = offgraphics.getFontMetrics();
    for (int i = 0 ; i < nnodes ; i++) {
    paintNode( offgraphics, nodes, fm); //or
    g.drawImage(offscreen, 0, 0, null);
    public synchronized boolean mouseDown(Event evt, int x, int y) {
    double bestdist = Double.MAX_VALUE;
    for (int i = 0 ; i < nnodes ; i++) {
    Node n = nodes;
    double dist = (n.x - x) * (n.x - x) + (n.y - y) * (n.y - y);
    if (dist < bestdist) {
    pick = n;
    bestdist = dist;
    pickfixed = pick.fixed;
    pick.fixed = true;
    pick.x = x;
    pick.y = y;
    repaint();
    return true;
    public synchronized boolean mouseDrag(Event evt, int x, int y) {
    pick.x = x;
    pick.y = y;
    repaint();
    return true;
    } //e-pubsyncmousedrag
    public synchronized boolean mouseUp(Event evt, int x, int y) {
    pick.x = x;
    pick.y = y;
    pick.fixed = pickfixed;
    pick = null;
    repaint();
    return true;
    public void start() {
    relaxer = new Thread(this);
    relaxer.start();
    public void stop() {
    relaxer.stop();
    public class Box extends Applet {
    GraphPanel panel;
    public void init() {
    setLayout(new BorderLayout());
    panel = new GraphPanel(this);
    add("Center", panel);
    Panel p = new Panel();
    add("South", p);
    p.add(new Button("Reposition"));
    p.add(new Button("NewUrl"));
    p.add(new Checkbox("Showit"));
    String edges = getParameter("edges"); // putinli
    for (StringTokenizer t = new StringTokenizer(edges, ",") ; t.hasMoreTokens() ; ) {
    String str = t.nextToken();
    int i = str.indexOf('-');
    if (i > 0) { int len = 50;
    int j = str.indexOf('/');
    if (j > 0) {
    len = Integer.valueOf(str.substring(j+1)).intValue();
    str = str.substring(0, j);
    panel.addEdge(str.substring(0,i), str.substring(i+1), len);
    } //ef8
    Dimension d = size();
    String center = getParameter("center");
    if (center != null){
    Node n = panel.nodes[panel.findNode(center)];
    n.x = d.width / 2;
    n.y = d.height / 2;
    n.fixed = true;
    } // eif
    } // ep
    public void start() {
    panel.start();
    public void stop() {
    panel.stop();
    public boolean action(Event evt, Object arg) {
    if (arg instanceof Boolean) {
    if (((Checkbox)evt.target).getLabel().equals("Showit")) {
    panel.showit = ((Boolean)arg).booleanValue();
    }// e-
    else {
    panel.random = ((Boolean)arg).booleanValue();
    return true;
    } // e-if instof bool
    if ("Reposition".equals(arg)) {
    Dimension d = size();
    for (int i = 0 ; i < panel.nnodes ; i++) {
    Node n = panel.nodes;
    if (!n.fixed) {
    n.x = 10 + (d.width-20)*Math.random();
    n.y = 10 + (d.height-20)*Math.random();
    } //ei
    } //ef9
    return true;
    } //eif scram
    if ("NewUrl".equals(arg)) {
    Dimension d = size();
    URL url = getCodeBase();
    try {
    getAppletContext().showDocument( new URL(url+"main.htm"), "_blank" );
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) { }
    } catch(MalformedURLException e) {
    showStatus("814 URL not found");
    for (int i = 0 ; i < panel.nnodes ; i++) {
    Node n = panel.nodes;
    if (!n.fixed) {
    n.x += (80*0.02) - 40;
    n.y += (80*0.02) - 40;
    return true;
    } //ei
    return false;
    -----------------------htm file to launch------------------------------
    <html>
    <head>
    <title>R
    </title>
    </head>
    <body>
    <h3>
    <center>
    R
    </center>
    </h3>
    I
    <b>
    </b>
    <table border = 1>
    <td>De<td>Test List<tr>
    <td>N <td><tr>
    <td>N <td><tr>
    </table>
    <b>view </b>
    <applet code="Box.class" CODEBASE=. width=1000 height=600
    ALT="Test ">
    <param name=edges value="http:xxabc.htm-http:xxnet.htm,http:xxthis.htm-http:xx.comet.htm,http:xxnewsighting.htm-http:xxstar.htm,http:xxmoon.htm-http:xxNeptune.htm">
    <hr>
    </applet>
    </b>
    <p>
    <table border = 1>
    <tr>
    <tr>
    </table>
    </html>
    </body>
    instructions to compile :
    0 : The discussion becomes easy to follow after 1st compiling
    & viewing the applet.
    1. : cut out applet code.
    2. : the post somehow deleted all references to "" <--- HERE
    see, the data has been deleted again as I preview this post.
    ( that "" should contain an "i" array increment argument:
    "open square bracket" "i" "close square bracket" ) array
    so "javac Box.java" will get 10 errors. These "[" "i" "]"
    array args must be replaced to compile the code.
    3. : All array variables inside the 10 "for" loops ( the bare words
    "edges" and "nodes" ) without array increment "i" should
    read "edges" "[" "i" "]" & "nodes" "[" "i" "]".
    The 10 location lines are approx:
    line #65, #129, #136, #149, #195, #283, #311, #331, #477, #522
    4. : These 10 edits reqresent a missing "i" to all 10 for loop arrays.
    for eddges & nodes. fix this & javac Box.java" will get
    4 class files.
    5. : cut "Box.htm" from post & do "appletviewer Box.htm"
    or put in an apache "htdoc" or tomcat "servlet" http delivered
    directory & call "http://localhost/Box.htm.
    6. : of course, selecting the event button "NewUrl" will not
    work in appletviewer but will work in an http web location.
    7. : post your questions to problem or fixes to problem as I'm
    monitoring closely. TIA.

    Thanks for code post tip to fix array index deletion problem.
    Here is code reposted using "code" delimiters which will
    compile straight out of cut/paste.
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.*;
    import java.util.*;
    import java.awt.*;
    import java.applet.Applet;
    import java.applet.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.*;
    class Node {
    double x;
    double y;
    double dx;
    double dy;
    boolean fixed;
    String lbl;
    class Edge {
    int from;
    int to;
    double len;
    } // eEdgeCla
    class GraphPanel extends Panel implements Runnable {
    Box box;
    int nnodes;
    Node nodes[] = new Node[100];
    int nedges;
    Edge edges[] = new Edge[200];
    Thread relaxer;
    boolean showit;
    boolean random;
    GraphPanel(Box box) {
    this.box = box;
    } //ebox
    int findNode(String lbl) {
    for (int i = 0 ; i < nnodes ; i++) {
    //if (nodes.lbl.equals(lbl)) {
      if (nodes.lbl.equals(lbl)) {
    return i;
    return addNode(lbl);
    int addNode(String lbl) {
    Node n = new Node();
    n.x = 10 + 380*Math.random();
    n.y = 10 + 380*Math.random();
    n.lbl = lbl;
    nodes[nnodes] = n;
    return nnodes++;
    void addEdge(String from, String to, int len) {
    Edge e = new Edge();
    e.from = findNode(from);
    e.to = findNode(to);
    e.len = len;
    edges[nedges++] = e;
    public void run() {
    int i3=0;
    while (true) {
    relax();
    if (random && (Math.random() < 0.03)) {
    Node n = nodes[(int) (1 * nnodes) ]; // no
    if (!n.fixed) {
    n.x += (100*0.02) - 50;
    n.y += (100*0.02) - 50; //
    try {
    Thread.sleep(4000);
    } catch (InterruptedException e) {
    break;
    i3++;
    } //ew
    } // epublrun()
    synchronized void relax() {
    for (int i = 0 ; i < nedges ; i++) {
    //Edge e = edges;
    Edge e = edges[i];
    double vx = nodes[e.to].x - nodes[e.from].x;
    double vy = nodes[e.to].y - nodes[e.from].y;
    double len = Math.sqrt(vx * vx + vy * vy);
    //double f = (edges.len - len) / (len * 3) ;
    double f = (edges[i].len - len) / (len * 3) ;
    double dx = f * vx;
    double dy = f * vy;
    nodes[e.to].dx += dx;
    nodes[e.to].dy += dy;
    nodes[e.from].dx += -dx;
    nodes[e.from].dy += -dy;
    } //efo
    for (int i = 0 ; i < nnodes ; i++) {
    //Node n1 = nodes[i];
    Node n1 = nodes[i];
    double dx = 0;
    double dy = 0;
    for (int j = 0 ; j < nnodes ; j++) {
    if (i == j) {
    continue;
    Node n2 = nodes[j];
    double vx = n1.x - n2.x;
    double vy = n1.y - n2.y;
    double len = vx * vx + vy * vy;
    if (len == 0) {
    dx += 0.02;
    dy += 0.02;
    } else if (len < 100*100) {
    dx += vx / len;
    dy += vy / len;
    } //ef3a
    double dlen = dx * dx + dy * dy;
    if (dlen > 0) {
    dlen = Math.sqrt(dlen) / 2;
    n1.dx += dx / dlen;
    n1.dy += dy / dlen;
    } //ef3
    Dimension d = size();
    // f4
    for (int i = 0 ; i < nnodes ; i++) {
    //Node n = nodes;
    Node n = nodes[i];
    if (!n.fixed) {
    n.x += Math.max(-5, Math.min(5, n.dx));
    n.y += Math.max(-5, Math.min(5, n.dy));
    if (n.x < 0) {
    n.x = 0;
    } else if (n.x > d.width) {
    n.x = d.width;
    if (n.y < 0) {
    n.y = 0;
    } else if (n.y > d.height) {
    n.y = d.height;
    n.dx /= 2;
    n.dy /= 2;
    repaint();
    Node pick;
    boolean pickfixed;
    Image offscreen;
    Dimension offscreensize;
    Graphics offgraphics;
    final Color fixedColor = Color.green;
    final Color selectColor = Color.gray;
    final Color edgeColor = Color.black;
    final Color nodeColor = new Color(200, 90, 50);
    final Color showitColor = Color.gray;
    final Color arcColor1 = Color.black;
    final Color arcColor2 = Color.orange;
    final Color arcColor3 = Color.blue;
    public void paintNode( Graphics g, Node n, FontMetrics fm) {
    int x = (int)n.x;
    int y = (int)n.y;
    g.setColor((n == pick) ? selectColor : (n.fixed ? fixedColor : nodeColor));
    int w = fm.stringWidth(n.lbl) + 10;
    int h = fm.getHeight() + 4;
    g.fillRect(x - w/2, y - h / 2, w, h);
    g.setColor(Color.black);
    g.drawRect(x - w/2, y - h / 2, w-1, h-1);
    String doit = n.lbl.replace('x','/');
    g.drawString(doit, x - (w-10)/2, (y - (h-4)/2) + fm.getAscent());
    } // epa
    public synchronized void update(Graphics g) {
    Dimension d = size();
    if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) {
    offscreen = createImage(d.width, d.height);
    offscreensize = d;
    offgraphics = offscreen.getGraphics();
    offgraphics.setFont(getFont());
    offgraphics.setColor(getBackground());
    offgraphics.fillRect(0, 0, d.width, d.height);
    for (int i = 0 ; i < nedges ; i++) {
    //Edge e = edges;
    Edge e = edges[i];
    int x1 = (int)nodes[e.from].x;
    int y1 = (int)nodes[e.from].y;
    int x2 = (int)nodes[e.to].x;
    int y2 = (int)nodes[e.to].y;
    int len = (int)Math.abs(Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) - e.len);
    offgraphics.setColor((len < 10) ? arcColor1 : (len < 20 ? arcColor2 : arcColor3)) ;
    offgraphics.drawLine(x1, y1, x2, y2);
    if (showit) {
    String lbl = String.valueOf(len);
    offgraphics.setColor(showitColor);
    offgraphics.drawString("href= http://localhost:"+lbl, x1 + (x2-x1)/2, y1 + (y2-y1)/2);
    offgraphics.setColor(edgeColor);
    } //ef5
    FontMetrics fm = offgraphics.getFontMetrics();
    for (int i = 0 ; i < nnodes ; i++) {
    //paintNode( offgraphics, nodes, fm); //or
    paintNode( offgraphics, nodes[i], fm); //or
    g.drawImage(offscreen, 0, 0, null);
    public synchronized boolean mouseDown(Event evt, int x, int y) {
    double bestdist = Double.MAX_VALUE;
    for (int i = 0 ; i < nnodes ; i++) {
    //Node n = nodes;
    Node n = nodes[i];
    double dist = (n.x - x) * (n.x - x) + (n.y - y) * (n.y - y);
    if (dist < bestdist) {
    pick = n;
    bestdist = dist;
    pickfixed = pick.fixed;
    pick.fixed = true;
    pick.x = x;
    pick.y = y;
    repaint();
    return true;
    public synchronized boolean mouseDrag(Event evt, int x, int y) {
    pick.x = x;
    pick.y = y;
    repaint();
    return true;
    } //e-pubsyncmousedrag
    public synchronized boolean mouseUp(Event evt, int x, int y) {
    pick.x = x;
    pick.y = y;
    pick.fixed = pickfixed;
    pick = null;
    repaint();
    return true;
    public void start() {
    relaxer = new Thread(this);
    relaxer.start();
    public void stop() {
    relaxer.stop();
    public class Box extends Applet {
    GraphPanel panel;
    public void init() {
    setLayout(new BorderLayout());
    panel = new GraphPanel(this);
    add("Center", panel);
    Panel p = new Panel();
    add("South", p);
    p.add(new Button("Reposition"));
    p.add(new Button("NewUrl"));
    p.add(new Checkbox("Showit"));
    String edges = getParameter("edges"); // putinli
    for (StringTokenizer t = new StringTokenizer(edges, ",") ; t.hasMoreTokens() ; ) {
    String str = t.nextToken();
    int i = str.indexOf('-');
    if (i > 0) { int len = 50;
    int j = str.indexOf('/');
    if (j > 0) {
    len = Integer.valueOf(str.substring(j+1)).intValue();
    str = str.substring(0, j);
    panel.addEdge(str.substring(0,i), str.substring(i+1), len);
    } //ef8
    Dimension d = size();
    String center = getParameter("center");
    if (center != null){
    Node n = panel.nodes[panel.findNode(center)];
    n.x = d.width / 2;
    n.y = d.height / 2;
    n.fixed = true;
    } // eif
    } // ep
    public void start() {
    panel.start();
    public void stop() {
    panel.stop();
    public boolean action(Event evt, Object arg) {
    if (arg instanceof Boolean) {
    if (((Checkbox)evt.target).getLabel().equals("Showit")) {
    panel.showit = ((Boolean)arg).booleanValue();
    }// e-
    else {
    panel.random = ((Boolean)arg).booleanValue();
    return true;
    } // e-if instof bool
    if ("Reposition".equals(arg)) {
    Dimension d = size();
    for (int i = 0 ; i < panel.nnodes ; i++) {
    //Node n = panel.nodes;
    Node n = panel.nodes[i];
    if (!n.fixed) {
    n.x = 10 + (d.width-20)*Math.random();
    n.y = 10 + (d.height-20)*Math.random();
    } //ei
    } //ef9
    return true;
    } //eif scram
    if ("NewUrl".equals(arg)) {
    Dimension d = size();
    URL url = getCodeBase();
    try {
    getAppletContext().showDocument( new URL(url+"main.htm"), "_blank" );
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) { }
    } catch(MalformedURLException e) {
    showStatus("814 URL not found");
    for (int i = 0 ; i < panel.nnodes ; i++) {
    //Node n = panel.nodes;
    Node n = panel.nodes[i];
    if (!n.fixed) {
    n.x += (80*0.02) - 40;
    n.y += (80*0.02) - 40;
    return true;
    } //ei
    return false;

  • [ANN] XINS 2.1 open source Web Services framework release

    XINS 2.1 Web Services Framework has been released.
    XINS is an open source Web Services Framework based on simple specifications of the Web Service in XML and
    generation of code and documentation from the specification.
    The generation includes Client JAR with its Javadoc, Server side template with its Javadoc, documentation in OpenDocument Format,
    documentation in HTML including the test forms, WSDL file, unit tests (JUnit) and stubs.
    The Web Services accept several protocols including REST, SOAP, XML-RPC, XML, JSON Yahoo! and JSON-RPC.
    What's new:
    * Start the API with java -jar <api name>.war
    * Improved generated specification in OpenDocument Format
    * Include/exclude calling convention with ACLs
    * New calling convention that maps SOAP request and response as the wsdl2api command mapping.
    * Smaller generated build.xml
    * Added possibility to include other runtime properties files
    * The runtime property location can be a URL
    * Swing Graphical User Interface
    * New tools: emma, glean, webstart
    * New target: javadoc-test-<api name>, javadoc-apis
    * Bug fixes and small RFEs
    Download XINS 2.1:
    Windows installer: http://prdownloads.sf.net/xins/xins-2.1.exe?download
    TAR GZ archive: http://prdownloads.sf.net/xins/xins-2.1.tgz?download
    Resources:
    Web site: http://xins.sourceforge.net/
    XINS demos: http://xins.sourceforge.net/demo.html
    Documentation: http://xins.sourceforge.net/documentation.html
    User guide: http://xins.sourceforge.net/docs/index.html

    I recommend you implement your web service with JAX-WS 2.0
    Axis (both version) are good but why do you want to use something that is not included in JEE API, when Java provide same thing with better performance.
    personally try to prevent non standard technologies despite they can be better than core java implementation sometimes.
    I don't know Xfire.
    the good:
    -JAX-WS performance is better than axis,
    - you can create your web service simply with annotation.(this means write class and then make it as a service easily)
    - support every kind of service invocation(callback,Asynchronous,...)
    - architecture is nice (you can operate on SOAP level)
    the Bad:
    - It is JEE 5 or JSE 6 dependent.
    - there is seriously lack of documentation and examples for it, on java web sites and internet.

Maybe you are looking for