Results 1 to 2 of 2
  1. #1
    caulsonchua is offline Member
    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    Default How to query data in from text file in jPanel ?

    Dear All,

    May i know how to query the data from text file to graph in jpanel when i select the year?


    i had use array function call the data from desktop text file and spool in the graph. kindly advise, thank yoi



    as below is my coding.








    NewGUI.Java

    Java Code:
    import java.awt.event.ActionEvent;
    
    
    public class NewGUI extends java.awt.Frame {
           static  NewUserSelectionHandling newuserSelectionHandling = new NewUserSelectionHandling();
           static String SelectedCompany="";
           static int SelectedYear=0;
           static int Selectedsimilar_trends=0;
     
            public NewGUI() {
                initComponents();
            }
     
            /**
             * This method is called from within the constructor to initialize the form.
             * WARNING: Do NOT modify this code. The content of this method is always
             * regenerated by the Form Editor.
             */
            // <editor-fold defaultstate="collapsed" desc="Generated Code">
            private void initComponents() {
     
                jLayeredPane1 = new javax.swing.JLayeredPane();
                jLabel1 = new javax.swing.JLabel();
                jLabel2 = new javax.swing.JLabel();
                jComboBox1 = new javax.swing.JComboBox();
                jLabel3 = new javax.swing.JLabel();
                jComboBox2 = new javax.swing.JComboBox();
                jLabel4 = new javax.swing.JLabel();
                jComboBox3 = new javax.swing.JComboBox();
                jButton1 = new javax.swing.JButton();
                jLabel5 = new javax.swing.JLabel();
                jLabel6 = new javax.swing.JLabel();
                jPanel1 = new javax.swing.JPanel();
                jLabel7 = new javax.swing.JLabel();
                jScrollPane1 = new javax.swing.JScrollPane();
                jLabel8 = new javax.swing.JLabel();
     
                addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent evt) {
                        exitForm(evt);
                    }
                });
     
                jLabel1.setBackground(new java.awt.Color(153, 204, 255));
                jLabel1.setFont(new java.awt.Font("Traditional Arabic", 1, 36)); // NOI18N
                jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
                jLabel1.setText("Stock Market Prices");
                jLabel1.setAutoscrolls(true);
                jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
                jLabel1.setRequestFocusEnabled(false);
                jLabel1.setBounds(110, 20, 340, 50);
                jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);
     
                jLabel2.setBackground(new java.awt.Color(153, 204, 255));
                jLabel2.setFont(new java.awt.Font("Traditional Arabic", 1, 18)); // NOI18N
                jLabel2.setForeground(new java.awt.Color(0, 102, 102));
                jLabel2.setText("Company");
                jLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
                jLabel2.setBounds(60, 94, 100, 30);
                jLayeredPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
     
                jComboBox1.setBackground(new java.awt.Color(153, 204, 255));
                jComboBox1.setEditable(true);
                jComboBox1.setFont(new java.awt.Font("Traditional Arabic", 1, 14)); // NOI18N
                jComboBox1.setForeground(new java.awt.Color(0, 102, 102));
                jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AFG-CG", "ASTINO", "AMTEK", "AMWAY" }));
                jComboBox1.setSelectedIndex(-1);
                jComboBox1.setAutoscrolls(true);
                jComboBox1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED, new java.awt.Color(255, 255, 204), new java.awt.Color(0, 204, 204), new java.awt.Color(0, 51, 102), new java.awt.Color(0, 102, 102)));
                jComboBox1.setBounds(60, 130, 100, 30);
                jComboBox1.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        jComboBox1ActionPerformed(evt);
                    }
                });
                jLayeredPane1.add(jComboBox1, javax.swing.JLayeredPane.DEFAULT_LAYER);
     
                jLabel3.setBackground(new java.awt.Color(153, 204, 255));
                jLabel3.setFont(new java.awt.Font("Traditional Arabic", 1, 18)); // NOI18N
                jLabel3.setForeground(new java.awt.Color(0, 102, 102));
                jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
                jLabel3.setText("Year");
                jLabel3.setFocusable(false);
                jLabel3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
                jLabel3.setBounds(214, 90, 80, 30);
                jLayeredPane1.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);
     
                jComboBox2.setBackground(new java.awt.Color(153, 204, 255));
                jComboBox2.setEditable(true);
                jComboBox2.setFont(new java.awt.Font("Traditional Arabic", 1, 14)); // NOI18N
                jComboBox2.setForeground(new java.awt.Color(0, 102, 102));
                jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2010", "2011", "2012" }));
                jComboBox2.setSelectedIndex(-1);
                jComboBox2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED, new java.awt.Color(255, 255, 204), new java.awt.Color(0, 204, 204), new java.awt.Color(0, 51, 102), new java.awt.Color(0, 102, 102)));
                jComboBox2.setBounds(210, 130, 90, 30);
                jComboBox2.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        jComboBox2ActionPerformed(evt);
                    }
                });
                jLayeredPane1.add(jComboBox2, javax.swing.JLayeredPane.DEFAULT_LAYER);
     
                jLabel4.setBackground(new java.awt.Color(153, 204, 255));
                jLabel4.setFont(new java.awt.Font("Traditional Arabic", 1, 18)); // NOI18N
                jLabel4.setForeground(new java.awt.Color(0, 102, 102));
                jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
                jLabel4.setText("Similar Tend(s)");
                jLabel4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
                jLabel4.setBounds(350, 90, 130, 30);
                jLayeredPane1.add(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);
     
                jComboBox3.setBackground(new java.awt.Color(153, 204, 255));
                jComboBox3.setEditable(true);
                jComboBox3.setFont(new java.awt.Font("Traditional Arabic", 1, 14)); // NOI18N
                jComboBox3.setForeground(new java.awt.Color(0, 153, 153));
                jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5" }));
                jComboBox3.setSelectedIndex(-1);
                jComboBox3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED, new java.awt.Color(255, 255, 204), new java.awt.Color(0, 204, 204), new java.awt.Color(0, 51, 102), new java.awt.Color(0, 102, 102)));
                jComboBox3.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
                jComboBox3.setBounds(350, 130, 90, 30);
                jComboBox3.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        jComboBox3ActionPerformed(evt);
                    }
                });
                jLayeredPane1.add(jComboBox3, javax.swing.JLayeredPane.DEFAULT_LAYER);
     
                jButton1.setBackground(new java.awt.Color(153, 204, 255));
                jButton1.setFont(new java.awt.Font("Traditional Arabic", 1, 20)); // NOI18N
                jButton1.setForeground(new java.awt.Color(102, 102, 102));
                jButton1.setText("SUBMIT");
                jButton1.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, new java.awt.Color(102, 0, 51), new java.awt.Color(102, 0, 51)));
                jButton1.setBorderPainted(false);
                jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
                jButton1.setBounds(443, 180, 100, 30);
                jLayeredPane1.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);
                jButton1.addActionListener(new java.awt.event.ActionListener() {
     
     
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        jButton1ActionPerformed(evt);
                    }
                });
     
                jLabel5.setFont(new java.awt.Font("Traditional Arabic", 1, 18)); // NOI18N
                jLabel5.setForeground(new java.awt.Color(0, 51, 102));
                jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
                jLabel5.setText("Company: ");
                jLabel5.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
                jLabel5.setBounds(40, 210, 90, 30);
                jLayeredPane1.add(jLabel5, javax.swing.JLayeredPane.DEFAULT_LAYER);
     
                jLabel6.setFont(new java.awt.Font("Traditional Arabic", 1, 18)); // NOI18N
                jLabel6.setForeground(new java.awt.Color(0, 51, 102));
                jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
                jLabel6.setText("ASTINO");
                jLabel6.setToolTipText("");
                jLabel6.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
                jLabel6.setBounds(130, 220, 80, 20);
                jLayeredPane1.add(jLabel6, javax.swing.JLayeredPane.DEFAULT_LAYER);
     
                jPanel1.setBackground(new java.awt.Color(255, 255, 255));
                jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(153, 153, 153), 1, true));
                jPanel1.setForeground(new java.awt.Color(204, 204, 204));
                jPanel1.setAutoscrolls(true);
                jPanel1.setFont(new java.awt.Font("Traditional Arabic", 1, 18)); // NOI18N
                jPanel1.setBounds(30, 240, 510, 180);
                jLayeredPane1.add(jPanel1, javax.swing.JLayeredPane.DEFAULT_LAYER);
     
                jLabel7.setFont(new java.awt.Font("Traditional Arabic", 1, 18)); // NOI18N
                jLabel7.setForeground(new java.awt.Color(0, 51, 102));
                jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
                jLabel7.setText("Similar Tend(s) company: ");
                jLabel7.setBounds(30, 430, 220, 30);
                jLayeredPane1.add(jLabel7, javax.swing.JLayeredPane.DEFAULT_LAYER);
     
                jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
                jScrollPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
                jScrollPane1.setForeground(new java.awt.Color(255, 255, 255));
                jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
                jScrollPane1.setAutoscrolls(true);
                jScrollPane1.setFont(new java.awt.Font("Traditional Arabic", 1, 14)); // NOI18N
                jScrollPane1.setBounds(30, 460, 520, 200);
                jLayeredPane1.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);
     
                jLabel8.setBackground(new java.awt.Color(153, 204, 255));
                jLabel8.setFont(new java.awt.Font("Traditional Arabic", 1, 10)); // NOI18N
                jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
                jLabel8.setText("[C] Copyright 2013, Law Hui Kim");
                jLabel8.setBounds(0, 670, 290, 17);
                jLayeredPane1.add(jLabel8, javax.swing.JLayeredPane.DEFAULT_LAYER);
     
                add(jLayeredPane1, java.awt.BorderLayout.CENTER);
     
                pack();
            }// </editor-fold>
     
            private void jButton1ActionPerformed(ActionEvent evt){
            //**!!ss.ChoiceOfCompany(SelectedCompany,SelectedYear, Selectedsimilar_trends);
            newuserSelectionHandling.UserSelection(SelectedCompany,SelectedYear, Selectedsimilar_trends);
     
        }
     
        private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            SelectedCompany=jComboBox1.getSelectedItem().toString();
     
     
        }
     
        private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt){
            //  SelectedYear= ((Integer)jComboBox2.getSelectedItem()).intValue();
            SelectedYear= Integer.parseInt(jComboBox2.getSelectedItem().toString());
        }
     
        private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt){
            Selectedsimilar_trends=Integer.parseInt(jComboBox3.getSelectedItem().toString());
        }
     
     
            /**
             * Exit the Application
             */
            private void exitForm(java.awt.event.WindowEvent evt) {
                System.exit(0);
            }
     
            /**
             * @param args the command line arguments
             */
     
     
            public static void main(String args[]) {
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        NewGUI ng = new NewGUI();
                        ng.setSize(600,725);
                        ng.setVisible(true);
     
                    }
                });
            }
            // Variables declaration - do not modify
            private javax.swing.JButton jButton1;
            private javax.swing.JComboBox jComboBox1;
            private javax.swing.JComboBox jComboBox2;
            private javax.swing.JComboBox jComboBox3;
            private javax.swing.JLabel jLabel1;
            private javax.swing.JLabel jLabel2;
            private javax.swing.JLabel jLabel3;
            private javax.swing.JLabel jLabel4;
            private javax.swing.JLabel jLabel5;
            private javax.swing.JLabel jLabel6;
            private javax.swing.JLabel jLabel7;
            private javax.swing.JLabel jLabel8;
            private javax.swing.JLayeredPane jLayeredPane1;
            private javax.swing.JPanel jPanel1;
            private javax.swing.JScrollPane jScrollPane1;
            // End of variables declaration













    NewUserSelect.Java

    Java Code:
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.text.DecimalFormat;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
     
    
    public class NewUserSelectionHandling  {
     
        static List<Double> closeBidsGet;
        static GraphDrawing graphDrawing;
        static DecimalFormat decimalFormat = new DecimalFormat("#.##");
        static double [] closing_bids;
     
        public NewUserSelectionHandling(){
            closeBidsGet = new ArrayList<Double>();
        }
     
        public static void UserSelection ( String SelectedCompany, Integer SelectedYear, Integer Selectedsimilar_trends){
     
            if(SelectedCompany.equals("") && SelectedYear!=0 && Selectedsimilar_trends !=0){
                     MissingCompanySelection mcs = new MissingCompanySelection();
                     mcs.RunIt();
            }
            else if(SelectedCompany.equals("") && SelectedYear==0 && Selectedsimilar_trends!=0){
                    MissingCompanyAndYearSelection mcys = new MissingCompanyAndYearSelection();
                    mcys.RunIt();
            }
            else if((!SelectedCompany.equals("")) && SelectedYear==0 && Selectedsimilar_trends==0){
                     MissingYearAndSimilarTrendSelection myss = new MissingYearAndSimilarTrendSelection();
                    myss.RunIt();
            }
            else if ((!SelectedCompany.equals("")) && SelectedYear!=0 && Selectedsimilar_trends==0){
                    MissingSimilarTrendSelection mss = new MissingSimilarTrendSelection();
                    mss.RunIt();
            }
            else if ((!SelectedCompany.equals("")) && SelectedYear==0 && Selectedsimilar_trends!=0){
                    MissingYearSelection mys = new MissingYearSelection();
                    mys.RunIt();
            }
            else if (SelectedCompany.equals("") && SelectedYear!=0 && Selectedsimilar_trends==0){
                    MissingCompanyAndSimilarTrendSelection mcss = new MissingCompanyAndSimilarTrendSelection();
                    mcss.RunIt();
            }
            else{
     
            switch(SelectedYear){
                case 2010:
                    File folder_path = new File("C:/Users/weekeong.chua/Desktop/Result/2010");
                    File[] ListofTextFiles = folder_path.listFiles();
     
                    for (int i = 0; i<ListofTextFiles.length; i++ ){
                        int temp = ListofTextFiles[i].getName().lastIndexOf(".");
     
                        if (temp>0){
                            String company = ListofTextFiles[i].getName().substring(0,temp);
     
                            if (SelectedCompany.equals(company)){
                                try{
                                    Scanner readTextFileContent = new Scanner(new FileInputStream("C:/Users/weekeong.chua/Desktop/Result/2010/"+company+".txt"));
                                    while(readTextFileContent.hasNextLine()){
                                        String []resultCompanyNameGet = readTextFileContent.nextLine().split(" ");
     
                                        for (int x=0; x<Selectedsimilar_trends; x++){
                                            String companyName = resultCompanyNameGet[x];
                                            readTextFileContent = new Scanner (new FileInputStream("C:/Users/weekeong.chua/Desktop/CloseBids/2010/"+companyName+".txt"));
     
                                            while (readTextFileContent.hasNextLine()){
                                                String [] tmp = readTextFileContent.nextLine().split(" ");
                                                closeBidsGet.add(Double.parseDouble((tmp[2])));
                                            }
     
                                            //graphDrawing.main(closeBidsGet);
                                           // closeBidsGet.clear();
                                           graphDrawing = new GraphDrawing(closeBidsGet);
                                            graphDrawing.main(closeBidsGet);
                                        }
                                    }
                                    readTextFileContent.close();
                                } catch (FileNotFoundException e) {
                                    e.printStackTrace();
                                }
                            }
     
                        }
                    }
                    break;
     
                case 2011:
                    File folder_path1 = new File("C:/Users/weekeong.chua/Desktop/Result/2011");
                    File[] ListofTextFiles1 = folder_path1.listFiles();
     
                    for (int i = 0; i<ListofTextFiles1.length; i++ ){
                        int temp1 = ListofTextFiles1[i].getName().lastIndexOf(".");
     
                        if (temp1>0){
                            String company1 = ListofTextFiles1[i].getName().substring(0,temp1);
     
                            if (SelectedCompany.equals(company1)){
                                try{
                                    Scanner readTextFileContent1 = new Scanner(new FileInputStream("C:/Users/weekeong.chua/Desktop/Result/2011/"+company1+".txt"));
                                    while(readTextFileContent1.hasNextLine()){
                                        String []resultCompanyNameGet1 = readTextFileContent1.nextLine().split(" ");
     
                                        for (int x=0; x<Selectedsimilar_trends; x++){
                                            String companyName1 = resultCompanyNameGet1[x];
                                            readTextFileContent1 = new Scanner (new FileInputStream("C:/Users/weekeong.chua/Desktop/CloseBids/2011/"+companyName1+".txt"));
     
                                            while (readTextFileContent1.hasNextLine()){
                                                String [] tmp1 = readTextFileContent1.nextLine().split(" ");
                                                closeBidsGet.add(Double.parseDouble((tmp1[2])));
                                            }
     
                                            //graphDrawing.main(closeBidsGet);
                                            //closeBidsGet.clear();
                                            graphDrawing = new GraphDrawing(closeBidsGet);
                                            graphDrawing.main(closeBidsGet);
     
                                        }
                                    }
                                    readTextFileContent1.close();
                                } catch (FileNotFoundException e) {
                                    e.printStackTrace();
                                }
                            }
     
                        }
                    }
                    break;
     
                case 2012:
                    File folder_path2 = new File("C:/Users/weekeong.chua/Desktop/Result/2012");
                    File[] ListofTextFiles2 = folder_path2.listFiles();
     
                    for (int i = 0; i<ListofTextFiles2.length; i++ ){
                        int temp2 = ListofTextFiles2[i].getName().lastIndexOf(".");
     
                        if (temp2>0){
                            String company2 = ListofTextFiles2[i].getName().substring(0,temp2);
     
                            if (SelectedCompany.equals(company2)){
                                try{
                                    Scanner readTextFileContent2 = new Scanner(new FileInputStream("C:/Users/weekeong.chua/Desktop/Result/2011/"+company2+".txt"));
                                    while(readTextFileContent2.hasNextLine()){
                                        String []resultCompanyNameGet2 = readTextFileContent2.nextLine().split(" ");
     
                                        for (int x=0; x<Selectedsimilar_trends; x++){
                                            String companyName2 = resultCompanyNameGet2[x];
                                            readTextFileContent2 = new Scanner (new FileInputStream("C:/Users/weekeong.chua/Desktop/CloseBids/2011/"+companyName2+".txt"));
     
                                            while (readTextFileContent2.hasNextLine()){
                                                String [] tmp1 = readTextFileContent2.nextLine().split(" ");
                                                closeBidsGet.add(Double.parseDouble(decimalFormat.format(tmp1[2].toString())));
                                            }
     
                                            //graphDrawing.DrawTheGraph(closeBidsGet);
                                            //closeBidsGet.clear();
                                            graphDrawing = new GraphDrawing(closeBidsGet);
                                            graphDrawing.main(closeBidsGet);
     
                                        }
                                    }
                                    readTextFileContent2.close();
                                } catch (FileNotFoundException e) {
                                    e.printStackTrace();
                                }
                            }
     
                        }
                    }
                    break;
            }
     
            }
       }
     
     
     
     
     
    }











    DrawingGraph.Java

    Java Code:
    
    
    import javax.swing.*;
    import java.awt.*;
    import java.awt.font.FontRenderContext;
    import java.awt.font.LineMetrics;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Line2D;
    import java.util.ArrayList;
    import java.util.List;
     
    
    public class GraphDrawing extends JPanel {
     
       // public static void DrawTheGraph(List<Double>closeBidsGet){
          /*for (Double closebidsget: closeBidsGet)
            System.out.println(closebidsget);  */
     
     
     
     
     
           // public class GraphDrawing extends JPanel {
     
                List<Double> closing_bids;
     
     
                public GraphDrawing(List<Double>closeBidsGet){
                    closing_bids= closeBidsGet;
     
                }
     
                final int     PAD = 50;
     
                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();
     
                    String s=" ";
                    g2.drawString(s,PAD,PAD-10);
                    // 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.
                    s = "CLOSING BIDS";
                    float sy = PAD + ((h - 2*PAD) - s.length()*sh)/2 + lm.getAscent();
                    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, sy);
                        sy += sh;
                    }
                    // Abcissa label.
                    s = "YEAR:2010";
                    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);
                    // Draw lines.
                    double xInc = (double)(w - 2*PAD)/(closing_bids.size()-1);
                    double scale = (double)(h - 2*PAD)/(getMax()-getMin()+0.03);
                    g2.setPaint(Color.green.darker());
                    for(int i = 0; i < closing_bids.size()-1; i++) {
                        double x1 = PAD + i*xInc;
                        double y1 = h - PAD - scale*(closing_bids.get(i)-getMin()+0.03);
                        double x2 = PAD + (i+1)*xInc;
                        double y2 = h - PAD - scale*(closing_bids.get(i+1)-getMin()+0.03);
                        g2.draw(new Line2D.Double(x1, y1, x2, y2));
                    }
                    // Mark data points.
                    g2.setPaint(Color.BLUE);
                    for(int i = 0; i < closing_bids.size(); i++) {
                        double x = PAD + i*xInc;
                        double y = h - PAD - scale*(closing_bids.get(i)-getMin()+0.03);
                        g2.fill(new Ellipse2D.Double(x-2, y-2, 2.5, 2.5));
                    }
                }
     
                private double getMax() {
                    double max = -Double.MAX_VALUE;
                    for(int i = 0; i < closing_bids.size(); i++) {
                        if(closing_bids.get(i) > max)
                            max = closing_bids.get(i);
                    }
                    return max;
                }
     
                private double getMin() {
                    double min = Double.MAX_VALUE;
                    for(int i = 0; i < closing_bids.size(); i++) {
                        if(closing_bids.get(i) < min)
                            min = closing_bids.get(i);
                    }
                    return min;
                }
     
                public void main(List<Double> a) {
                    JFrame f = new JFrame();
                    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    f.add(new GraphDrawing(a));
                    f.setSize(900,400);
                    //f.setLocation(200,200);
                    f.setVisible(true);
                }
     
            }
     
     
     
     
       // }
     
     
    //}





    How to query data in from text file in jPanel ?-java.jpg

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,912
    Rep Power
    5

    Default Re: How to query data in from text file in jPanel ?

    Also posted in New to Java --> How to query data in from text file in jPanel ?

    Regards,
    Jim
    Last edited by jim829; 10-07-2013 at 04:46 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. How to query data in from text file in jPanel ?
    By caulsonchua in forum New To Java
    Replies: 1
    Last Post: 10-07-2013, 04:46 PM
  2. loading data from a text file
    By newbie123 in forum JDBC
    Replies: 1
    Last Post: 06-21-2011, 07:09 PM
  3. Replies: 2
    Last Post: 03-25-2011, 03:36 PM
  4. Replies: 6
    Last Post: 12-01-2010, 06:31 AM
  5. Replies: 1
    Last Post: 11-09-2010, 10:28 AM

Tags for this Thread

Posting Permissions

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