Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2010
    Posts
    1
    Rep Power
    0

    Default Scientific Graphing

    hello sir,, this is shruthi pursuing my final year BE in CSE. we are supposed to do an academic proj, so we have chosen Java as our platform.The project is
    SCIENTIFIC GRAPHING using JAVA. we have managed to get a graph, but got stuck in getting different formats of plotting say, it may be a (dot,'+', or a square etc...).here is the program which consists of the graph, along with that we have added a dialog box also to change the xaxis label and y axis label ,,, but getting some errors:(:( Kindly help us and do the needful... its very urgent.



    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    import javax.swing.JOptionPane.*;
    import java.awt.event.*;

    public class Trial8 extends JFrame implements ActionListener

    {
    JTextArea ta;
    JButton openBtn, subBtn, canBtn;
    static JPanel leftPan = new JPanel( new BorderLayout( ) );
    JPanel btnPan, textPan;
    JFileChooser fc;
    GraphPanel gPan;
    JPopupMenu popup;
    // JDialog dia;
    String Xlabel,Ylabel;

    public Trial8( )
    {
    //dia = new JDialog( this, "Messge Displayed", true );

    setLayout( new GridLayout( 1,2 ) );
    ta = new JTextArea( 60, 20 );
    ta.setMargin(new Insets(5,5,5,5));
    ta.setEditable(true);
    JScrollPane logScrollPane = new JScrollPane(ta);
    ta.setLineWrap(false);

    popup = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem("+");
    menuItem.addActionListener(this);
    popup.add(menuItem);
    menuItem = new JMenuItem("#");
    menuItem.addActionListener(this);
    popup.add(menuItem);

    //Add listener to the text area so the popup menu can come up.
    MouseListener popupListener = new PopupListener(popup);
    this.addMouseListener(popupListener);

    openBtn = new JButton( "OpenFile" );
    subBtn = new JButton( "Submit" );
    canBtn = new JButton( "Cancel" );
    btnPan = new JPanel( new FlowLayout( ) );
    textPan = new JPanel( new BorderLayout( ) );

    textPan.add( ta );
    btnPan.add( openBtn );
    btnPan.add( subBtn );
    btnPan.add( canBtn );
    leftPan.add( "Center", textPan );
    leftPan.add( "South", btnPan );

    openBtn.addActionListener( this );
    subBtn.addActionListener( this );
    canBtn.addActionListener( this );

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout( new GridLayout( 1, 2) );
    add( leftPan );
    gPan = new GraphPanel( );
    add( gPan );
    setSize(1250,650);
    setLocation(10,10);
    setVisible(true);
    }

    public void actionPerformed( ActionEvent ae )
    {
    if( ae.getSource( ) == openBtn )
    {
    fc = new JFileChooser( );
    System.out.println( "open btn pressed" );
    fc.showOpenDialog(Trial8.this);
    try
    {
    File file = fc.getSelectedFile();
    FileInputStream infile = new FileInputStream( file.getName( ) );
    BufferedReader reader = new BufferedReader( new InputStreamReader( infile ) );
    // Read first line X-axis values from given input file
    String line;
    ta.setText( "" );
    while( ( line = reader.readLine( ) ) != null )
    {
    ta.append( line + "\n" );
    }
    }
    catch( Exception e )
    {
    System.out.println( e );
    }
    }
    else if ( ae.getSource( ) == subBtn )
    {
    String taText = ta.getText( );
    StringTokenizer taTokens = new StringTokenizer( taText, "\n" );
    String first = taTokens.nextToken( );
    String second = taTokens.nextToken( );

    StringTokenizer tokens = new StringTokenizer( first );
    int count = tokens.countTokens( );
    gPan.data_x = new int[count];
    gPan.data_y = new int[count];

    for( int i=0; i<count; i++ )
    {
    gPan.data_x[i] = Integer.valueOf( tokens.nextToken( ) );
    System.out.print( " " + gPan.data_x[i] );
    }

    System.out.println( );

    // Read Second line Y-axis values from given input file
    tokens = new StringTokenizer( second );
    count = tokens.countTokens( );

    for( int i=0; i<count; i++ )
    {
    gPan.data_y[i] = Integer.valueOf( tokens.nextToken( ) );
    System.out.print( " " + gPan.data_y[i] );
    }
    }
    else if ( ae.getSource( ) == canBtn )
    {
    System.out.println( "Cancel btn pressed" );
    }
    gPan.repaint( );
    }

    public static void main(String[] args)
    {
    new Trial8( );
    }
    }



    class GraphPanel extends JPanel
    {
    int data_x[], data_y[]; // data[][]
    final int PAD = 40;
    public JOptionPane ShowInputDialog;
    String Xlabel,Ylabel;

    // Space between axis and label.

    public GraphPanel( )
    {
    try
    {
    // Create a file input stream object and assign input file name
    FileInputStream fin = new FileInputStream( "data3.txt" );
    BufferedReader reader = new BufferedReader(new InputStreamReader(fin));

    // Read first line X-axis values from given input file
    String line = reader.readLine();
    StringTokenizer tokens = new StringTokenizer( line );
    int count = tokens.countTokens( );
    data_x = new int[count];
    data_y = new int[count];

    for( int i=0; i<count; i++ )
    {
    data_x[i] = Integer.valueOf( tokens.nextToken( ) );
    System.out.print( " " + data_x[i] );
    }

    System.out.println( );

    // Read Second line Y-axis values from given input file
    line = reader.readLine();
    tokens = new StringTokenizer( line );
    count = tokens.countTokens( );

    for( int i=0; i<count; i++ )
    {
    data_y[i] = Integer.valueOf( tokens.nextToken( ) );
    System.out.print( " " + data_y[i] );
    }
    }
    catch( Exception e )
    {
    System.out.println( e );
    }

    }

    protected void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASIN G,RenderingHints.VALUE_ANTIALIAS_ON);
    int w = getWidth();
    int h = getHeight();

    // Draw ordinate.
    g2.draw(new Line2D.Double(PAD, PAD, PAD, h-PAD));

    // Draw abcissa.
    g2.draw(new Line2D.Double(PAD, h-PAD, w-PAD, h-PAD));

    // Draw labels.
    Font font = g2.getFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = font.getLineMetrics("0", frc);
    float sh = lm.getAscent() + lm.getDescent();

    // Ordinate label.
    String s = Ylabel; //tf1.getText( );
    float sy = PAD + ((h - 2*PAD) - s.length()*sh)/2 + lm.getAscent();

    g2.setPaint(Color.red);
    for(int i = 0; i < s.length(); i++)
    {
    String letter = String.valueOf(s.charAt(i));
    float sw = (float)font.getStringBounds(letter, frc).getWidth();
    float sx = (PAD - sw)/2;
    g2.drawString(letter, sx-10, sy);
    sy += sh;
    }

    // Abcissa label.
    s = Xlabel;
    sy = h - PAD + (PAD - sh)/2 + lm.getAscent();
    float sw = (float)font.getStringBounds(s, frc).getWidth();
    float sx = (w - sw)/2;
    g2.drawString(s, sx, sy+5);

    // Draw lines.
    double xInc = (double)(w - 2*PAD)/(data_x.length-1);
    double scale = (double)(h - 2*PAD)/getMaxX();
    g2.setPaint(Color.green.darker());
    for(int i = 0; i < data_x.length-1; i++)
    {
    double x1 = PAD + scale*data_x[i];
    double y1 = h - PAD - scale*data_y[i];
    double x2 = PAD + scale*data_x[i+1];
    double y2 = h - PAD - scale*data_y[i+1];
    g2.draw(new Line2D.Double(x1, y1, x2, y2));


    }

    // Draw Vertical Yellow Lines
    for(int i = 5; i <= getMaxX()+5; i+=5)
    {
    double x1 = PAD + scale*i;
    double y1 = h - PAD;
    double x2 = PAD + scale*i;
    double y2 = PAD;
    g2.setPaint(Color.yellow);
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    g2.setPaint(Color.blue);
    g2.fill(new Rectangle2D.Double(x1-2, y1-2, 4, 4));

    g2.setPaint(Color.black);
    s = String.valueOf(i);
    Double x_dou = new Double( x1-4 );
    Double y_dou = new Double( y1+15 );
    int x_dis = x_dou.intValue( );
    int y_dis = y_dou.intValue( );
    g.drawString(s, x_dis, y_dis);
    }

    // Draw Horizontal Yellow Lines
    for(int i = 5; i <= getMaxY()+5; i+=5)
    {
    double x1 = PAD;
    double y1 = h - PAD - scale*i;
    double x2 = w - PAD;
    double y2 = h - PAD - scale*i;
    g2.setPaint(Color.yellow);
    g2.draw(new Line2D.Double(x1, y1, x2, y2));

    g2.setPaint(Color.blue);
    g2.fill(new Ellipse2D.Double(x1-2, y1, 4, 4));

    g2.setPaint(Color.black);
    s = String.valueOf(i);
    Double x_dou = new Double( x1-20 );
    Double y_dou = new Double( y1+6 );
    int x_dis = x_dou.intValue( );
    int y_dis = y_dou.intValue( );
    g.drawString(s, x_dis, y_dis);
    }

    // Mark data points.
    g2.setPaint(Color.red);

    for(int i = 0; i < data_x.length; i++)
    {
    double x = PAD + scale*data_x[i];
    double y = h - PAD - scale*data_y[i];
    g2.fill(new Ellipse2D.Double(x-2, y-2, 4, 4));
    s = String.valueOf("("+data_x[i]+","+data_y[i]+")");
    Double x_dou = new Double( x );
    Double y_dou = new Double( y );
    int x_dis = x_dou.intValue( );
    int y_dis = y_dou.intValue( );
    g.drawString(s, x_dis, y_dis);
    // ****************** END Print Co-ord values *******************
    }
    repaint();


    }

    class MouseListener extends MouseAdapter{
    JOptionPane ShowDialog;
    public MouseListener(JOptionPane optionpane)
    {
    optionpane=ShowDialog;}


    public void mouseClicked(MouseEvent me)
    {

    if(me.getX()==0 && me.getY() == 0)
    {
    Xlabel=JOptionPane.ShowInputDialog("enter x-axis label");
    Ylabel=JOptionPane.ShowInputDialog("enter y-axis label");

    JOptionPane.ShowMessageDialog(null,"X and Y labels are entered","Labels confirmed",JOptionpane.INFORMATION_MESSAGE);
    }

    }
    }


    private int getMaxX()
    {
    int max = -Integer.MAX_VALUE;

    for(int i = 0; i < data_x.length; i++)
    {
    if(data_x[i] > max)
    max = data_x[i];
    }

    return max;
    }

    private int getMaxY()
    {
    int max = -Integer.MAX_VALUE;

    for(int i = 0; i < data_y.length; i++)
    {
    if(data_y[i] > max)
    max = data_y[i];
    }

    return max;
    }

    /*public class NestedPopupMenu
    {
    JPopupMenu Pmenu;
    JMenuItem Mitem;



    public NestedPopupMenu()
    {
    JFrame frame= new JFrame("creating Popup Menu");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    Pmenu= new JPopupMenu();
    Mitem=new JMenuItem("Line upIcon");
    Pmenu.add(Mitem);
    Mitem=new JMenuItem("Refresh");
    Pmenu.add(Mitem);
    Mitem=new JMenuItem("Properties");
    Pmenu.add(Mitem);
    Pmenu.add(createMenu("New"));

    frame.addMouseListener(new MouseAdapter(){
    public void mouseReleased(MouseEvent Me)
    {
    if(Me.isPopupTrigger())
    {
    Pmenu.show(Me. getComponent(), Me.getX(), Me.getY());
    }
    }
    });

    frame.setSize(400,400);
    frame.setVisible(true);
    }

    public JMenu createMenu(String title)
    {
    JMenu m=new JMenu(title);
    m.add("Folder");
    m.add("TextDocument");
    m.add("shortcut");
    return m;
    }
    }
    */
    }

    class PopupListener extends MouseAdapter {
    JPopupMenu popup;

    PopupListener(JPopupMenu popupMenu) {
    popup = popupMenu;
    }

    public void mousePressed(MouseEvent e) {
    maybeShowPopup(e);
    }

    public void mouseReleased(MouseEvent e) {
    maybeShowPopup(e);
    }

    private void maybeShowPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
    popup.show(e.getComponent(),
    e.getX(), e.getY());
    }
    }


    }
    Last edited by shruthi Nadiger; 03-14-2010 at 12:41 PM. Reason: had forgot to specify some information

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You may get quicker and helpful answers if you were to isolate your problem, then post a reasonable amount of code and then ask a specific question rather than a "here's a lot of code, please fix it for me" type post.

    Best of luck!

  3. #3
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    OK, So you misnamed some JOptionPane methods. Also, you cant leave XLabel and YLabel null you have to at least make them "". There is still the problem with the graph not being able to handle decimel points. But it runs:
    Java Code:
       import java.awt.*;
       import java.awt.event.*;
       import java.io.*;
       import java.util.*;
       import java.awt.font.*;
       import java.awt.geom.*;
       import javax.swing.*;
       import javax.swing.filechooser.*;
       import javax.swing.JOptionPane.*;
       import java.awt.event.*;
    
        public class Trial8 extends JFrame implements ActionListener
       
          {
          JTextArea ta;
          JButton openBtn, subBtn, canBtn;
          static JPanel leftPan = new JPanel( new BorderLayout( ) );
          JPanel btnPan, textPan;
          JFileChooser fc;
          GraphPanel gPan;
          JPopupMenu popup;
       // JDialog dia;
          String Xlabel,Ylabel;
       
           public Trial8( )
             {
          //dia = new JDialog( this, "Messge Displayed", true );
          
             setLayout( new GridLayout( 1,2 ) );
             ta = new JTextArea( 60, 20 );
             ta.setMargin(new Insets(5,5,5,5));
             ta.setEditable(true);
             JScrollPane logScrollPane = new JScrollPane(ta);
             ta.setLineWrap(false);
          
             popup = new JPopupMenu();
             JMenuItem menuItem = new JMenuItem("+");
             menuItem.addActionListener(this);
             popup.add(menuItem);
             menuItem = new JMenuItem("#");
             menuItem.addActionListener(this);
             popup.add(menuItem);
          
          //Add listener to the text area so the popup menu can come up.
             MouseListener popupListener = new PopupListener(popup);
             this.addMouseListener(popupListener);
          
             openBtn = new JButton( "OpenFile" );
             subBtn = new JButton( "Submit" );
             canBtn = new JButton( "Cancel" );
             btnPan = new JPanel( new FlowLayout( ) );
             textPan = new JPanel( new BorderLayout( ) );
          
             textPan.add( ta );
             btnPan.add( openBtn );
             btnPan.add( subBtn );
             btnPan.add( canBtn );
             leftPan.add( "Center", textPan );
             leftPan.add( "South", btnPan );
          
             openBtn.addActionListener( this );
             subBtn.addActionListener( this );
             canBtn.addActionListener( this );
          
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             setLayout( new GridLayout( 1, 2) );
             add( leftPan );
             gPan = new GraphPanel( );
             add( gPan );
             setSize(1250,650);
             setLocation(10,10);
             setVisible(true);
             }
       
           public void actionPerformed( ActionEvent ae )
             {
             if( ae.getSource( ) == openBtn )
                {
                fc = new JFileChooser( );
                System.out.println( "open btn pressed" );
                fc.showOpenDialog(Trial8.this);
                try
                   {
                   File file = fc.getSelectedFile();
                   FileInputStream infile = new FileInputStream( file.getName( ) );
                   BufferedReader reader = new BufferedReader( new InputStreamReader( infile ) );
                // Read first line X-axis values from given input file
                   String line;
                   ta.setText( "" );
                   while( ( line = reader.readLine( ) ) != null )
                      {
                      ta.append( line + "\n" );
                      }
                   }
                    catch( Exception e )
                      {
                      System.out.println( e );
                      }
                }
             else if ( ae.getSource( ) == subBtn )
                { 
                String taText = ta.getText( );
                StringTokenizer taTokens = new StringTokenizer( taText, "\n" );
                String first = taTokens.nextToken( );
                String second = taTokens.nextToken( );
             
                StringTokenizer tokens = new StringTokenizer( first );
                int count = tokens.countTokens( );
                gPan.data_x = new int[count];
                gPan.data_y = new int[count];
             
                for( int i=0; i<count; i++ )
                   {
                   gPan.data_x[i] = Integer.valueOf( tokens.nextToken( ) );
                   System.out.print( " " + gPan.data_x[i] );
                   }
             
                System.out.println( );
             
             // Read Second line Y-axis values from given input file
                tokens = new StringTokenizer( second );
                count = tokens.countTokens( );
             
                for( int i=0; i<count; i++ )
                   {
                   gPan.data_y[i] = Integer.valueOf( tokens.nextToken( ) );
                   System.out.print( " " + gPan.data_y[i] );
                   }
                }
             else if ( ae.getSource( ) == canBtn )
                {
                System.out.println( "Cancel btn pressed" );
                }
             gPan.repaint( );
             }
       
           public static void main(String[] args)
             {
             new Trial8( );
             }
          }
    
    
    
        class GraphPanel extends JPanel
          {
          int data_x[], data_y[]; // data[][]
          final int PAD = 40;
          public JOptionPane ShowInputDialog;
          String Xlabel = "Force(N)",Ylabel = "Length(m)";
       
       // Space between axis and label.
       
           public GraphPanel( )
             {
             try
                {
             // Create a file input stream object and assign input file name
                FileInputStream fin = new FileInputStream( "data3.txt" );
                BufferedReader reader = new BufferedReader(new InputStreamReader(fin));
             
             // Read first line X-axis values from given input file
                String line = reader.readLine();
                StringTokenizer tokens = new StringTokenizer( line );
                int count = tokens.countTokens( );
                data_x = new int[count];
                data_y = new int[count];
             
                for( int i=0; i<count; i++ )
                   {
                   data_x[i] = Integer.valueOf( tokens.nextToken( ) );
                   System.out.print( " " + data_x[i] );
                   }
             
                System.out.println( );
             
             // Read Second line Y-axis values from given input file
                line = reader.readLine();
                tokens = new StringTokenizer( line );
                count = tokens.countTokens( );
             
                for( int i=0; i<count; i++ )
                   {
                   data_y[i] = Integer.valueOf( tokens.nextToken( ) );
                   System.out.print( " " + data_y[i] );
                   }
                }
                 catch( Exception e )
                   {
                   System.out.println( e );
                   }
          
             }
       
           protected void paintComponent(Graphics g)
             {
             super.paintComponent(g);
             Graphics2D g2 = (Graphics2D)g;
             g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
             int w = getWidth();
             int h = getHeight();
          
          // Draw ordinate.
             g2.draw(new Line2D.Double(PAD, PAD, PAD, h-PAD));
          
          // Draw abcissa.
             g2.draw(new Line2D.Double(PAD, h-PAD, w-PAD, h-PAD));
          
          // Draw labels.
             Font font = g2.getFont();
             FontRenderContext frc = g2.getFontRenderContext();
             LineMetrics lm = font.getLineMetrics("0", frc);
             float sh = lm.getAscent() + lm.getDescent();
          
          // Ordinate label.
             String s = Ylabel; //tf1.getText( );
             int j =s.length();
             float sy = PAD + ((h - 2*PAD) - j*sh)/2 + lm.getAscent();
          
             g2.setPaint(Color.red);
             for(int i = 0; i < s.length(); i++)
                {
                String letter = String.valueOf(s.charAt(i));
                float sw = (float)font.getStringBounds(letter, frc).getWidth();
                float sx = (PAD - sw)/2;
                g2.drawString(letter, sx-10, sy);
                sy += sh;
                }
          
          // Abcissa label.
             s = Xlabel;
             sy = h - PAD + (PAD - sh)/2 + lm.getAscent();
             float sw = (float)font.getStringBounds(s, frc).getWidth();
             float sx = (w - sw)/2;
             g2.drawString(s, sx, sy+5);
          
          // Draw lines.
             double xInc = (double)(w - 2*PAD)/(data_x.length-1);
             double scale = (double)(h - 2*PAD)/getMaxX();
             g2.setPaint(Color.green.darker());
             for(int i = 0; i < data_x.length-1; i++)
                {
                double x1 = PAD + scale*data_x[i];
                double y1 = h - PAD - scale*data_y[i];
                double x2 = PAD + scale*data_x[i+1];
                double y2 = h - PAD - scale*data_y[i+1];
                g2.draw(new Line2D.Double(x1, y1, x2, y2));
             
             
                }
          
          // Draw Vertical Yellow Lines
             for(int i = 5; i <= getMaxX()+5; i+=5)
                {
                double x1 = PAD + scale*i;
                double y1 = h - PAD;
                double x2 = PAD + scale*i;
                double y2 = PAD;
                g2.setPaint(Color.yellow);
                g2.draw(new Line2D.Double(x1, y1, x2, y2));
                g2.setPaint(Color.blue);
                g2.fill(new Rectangle2D.Double(x1-2, y1-2, 4, 4));
             
                g2.setPaint(Color.black);
                s = String.valueOf(i);
                Double x_dou = new Double( x1-4 );
                Double y_dou = new Double( y1+15 );
                int x_dis = x_dou.intValue( );
                int y_dis = y_dou.intValue( );
                g.drawString(s, x_dis, y_dis);
                }
          
          // Draw Horizontal Yellow Lines
             for(int i = 5; i <= getMaxY()+5; i+=5)
                {
                double x1 = PAD;
                double y1 = h - PAD - scale*i;
                double x2 = w - PAD;
                double y2 = h - PAD - scale*i;
                g2.setPaint(Color.yellow);
                g2.draw(new Line2D.Double(x1, y1, x2, y2));
             
                g2.setPaint(Color.blue);
                g2.fill(new Ellipse2D.Double(x1-2, y1, 4, 4));
             
                g2.setPaint(Color.black);
                s = String.valueOf(i);
                Double x_dou = new Double( x1-20 );
                Double y_dou = new Double( y1+6 );
                int x_dis = x_dou.intValue( );
                int y_dis = y_dou.intValue( );
                g.drawString(s, x_dis, y_dis);
                }
          
          // Mark data points.
             g2.setPaint(Color.red);
          
             for(int i = 0; i < data_x.length; i++)
                {
                double x = PAD + scale*data_x[i];
                double y = h - PAD - scale*data_y[i];
                g2.fill(new Ellipse2D.Double(x-2, y-2, 4, 4));
                s = String.valueOf("("+data_x[i]+","+data_y[i]+")");
                Double x_dou = new Double( x );
                Double y_dou = new Double( y );
                int x_dis = x_dou.intValue( );
                int y_dis = y_dou.intValue( );
                g.drawString(s, x_dis, y_dis);
             // ****************** END Print Co-ord values *******************
                }
             repaint();
          
          
             }
       
           class MouseListener extends MouseAdapter{
             JOptionPane ShowDialog;
              public MouseListener(JOptionPane optionpane)
                {
                optionpane=ShowDialog;}
          
          
              public void mouseClicked(MouseEvent me)
                {
             
                if(me.getX()==0 && me.getY() == 0)
                   {
                   Xlabel=JOptionPane.showInputDialog("enter x-axis label");
                   Ylabel=JOptionPane.showInputDialog("enter y-axis label"); 
                
                   JOptionPane.showMessageDialog(null,"X and Y labels are entered","Labels confirmed",JOptionPane.INFORMATION_MESSAGE);
                   }
             
                }
             }
       
       
           private int getMaxX()
             {
             int max = -Integer.MAX_VALUE;
          
             for(int i = 0; i < data_x.length; i++)
                {
                if(data_x[i] > max)
                   max = data_x[i];
                }
          
             return max;
             }
       
           private int getMaxY()
             {
             int max = -Integer.MAX_VALUE;
          
             for(int i = 0; i < data_y.length; i++)
                {
                if(data_y[i] > max)
                   max = data_y[i];
                }
          
             return max;
             }
       
       /*public class NestedPopupMenu 
       {
       JPopupMenu Pmenu;
       JMenuItem Mitem;
       
       
       
       public NestedPopupMenu()
       {
       JFrame frame= new JFrame("creating Popup Menu");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
       Pmenu= new JPopupMenu();
       Mitem=new JMenuItem("Line upIcon");
       Pmenu.add(Mitem);
       Mitem=new JMenuItem("Refresh");
       Pmenu.add(Mitem);
       Mitem=new JMenuItem("Properties");
       Pmenu.add(Mitem);
       Pmenu.add(createMenu("New"));
       
       frame.addMouseListener(new MouseAdapter(){
       public void mouseReleased(MouseEvent Me)
       {
       if(Me.isPopupTrigger())
       {
       Pmenu.show(Me. getComponent(), Me.getX(), Me.getY());
       }
       }
       });
       
       frame.setSize(400,400);
       frame.setVisible(true);
       }
       
       public JMenu createMenu(String title)
       {
       JMenu m=new JMenu(title);
       m.add("Folder");
       m.add("TextDocument");
       m.add("shortcut");
       return m;
       }
       } 
       */ 
          }
    
        class PopupListener extends MouseAdapter {
          JPopupMenu popup;
       
           PopupListener(JPopupMenu popupMenu) {
             popup = popupMenu;
             }
       
           public void mousePressed(MouseEvent e) {
             maybeShowPopup(e);
             }
       
           public void mouseReleased(MouseEvent e) {
             maybeShowPopup(e);
             }
       
           private void maybeShowPopup(MouseEvent e) {
             if (e.isPopupTrigger()) {
                popup.show(e.getComponent(),
                          e.getX(), e.getY());
                }
             }
       
       
          }

Similar Threads

  1. Graphing in java
    By collin389 in forum New To Java
    Replies: 2
    Last Post: 01-18-2010, 01:54 AM
  2. Shared Scientific Toolbox in Java 1.01
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 05-08-2008, 06:53 PM
  3. Shared Scientific Toolbox in Java 1.00
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 04-10-2008, 04:16 PM
  4. Shared Scientific Toolbox in Java 0.99
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 03-16-2008, 08:38 PM
  5. Help with graphing problem
    By adlb1300 in forum New To Java
    Replies: 2
    Last Post: 11-26-2007, 02:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •