473,687 Members | 2,962 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading values from the file in Jpanel and creating a fuction

17 New Member
Hi,

I need help to automate my code to take data from input file. Also I need to create it as a function so that I can pass it to some other program. I am new to Java so having a bit limitation to do this.

My tab delimited Input File looks like this:-
21 p 13e 0 62 1 580001 andrew -14.53 -13.95 0 0
21 p 13d 63 124 580002 1160001 andrew -13.95 -13.37 0 0
21 p 12g 311 364 2900000 3385714 john -11.63 -11.14 0 0
21 q 11.1a 1274 1321 12300000 12750000 peter -2.23 -1.78 0 0

My program code has to store this data like this:-
Expand|Select|Wrap|Line Numbers
  1. g.drawRect(0,60,62,27);
  2. g.setColor(Color.black);
  3. g.fillRect(0,60,62,27);
  4. g.drawRect(63,60,61,27);
  5. g.setColor(Color.gray);
  6. g.fillRect(63,60,61,27);
but curretly I am manually entering this data. I am reading the 4rth and 5th field in my tab delimited input file and taking the difference of 4rth and 5th field as my 3rd value. Suppose in (0,60,62,27) my 3 value 62 is 0 - 62 etc. My 60 and 27 are almost constant for the whole data in (0,60,62,27) except for my highlighter for loop below.

Now one more important thing. I have created a special rectangle in my for loop which has to do the following:-
1) If a user enters any value between 580001 - 1160001 from command line which is from 6th and 7th fields in input file my for loop below should highlight that area in the rectangles, i.e, 63 to 124 which is it should set(63,60,61,27 ) values for my for loop. Suppose:-
Expand|Select|Wrap|Line Numbers
  1. int thickness = 5;
  2. g.setColor(Color.red);
  3. for (int i = 0; i < thickness; i++)
  4. g.draw3DRect(63 - i, 60 - i, 61 2 i, 27 2 i, true);
This should highlight the second rectangular block.

Also whenever there is suppose andrew in the line print black in my g.setColor(Colo r.black) for that line / suppose john print gray in my g.setColor(Colo r.black).

Currently my code looks like this:-
Expand|Select|Wrap|Line Numbers
  1. import java.awt.;
  2. import javax.swing.;
  3. import java.awt.Color;
  4. import java.awt.event.WindowAdapter;
  5. import java.awt.event.WindowEvent;
  6. import javax.swing.JFrame;
  7.  
  8. public class Myprogram extends JPanel {
  9. public void paintComponent(Graphics g) {
  10. super.paintComponent(g);
  11.  
  12. g.drawRect(0,60,62,27);
  13. g.setColor(Color.black);
  14. g.fillRect(0,60,62,27);
  15. g.drawRect(63,60,61,27);
  16. g.setColor(Color.gray);
  17. g.fillRect(63,60,61,27);
  18. g.drawRect(125,60,61,27);
  19. g.setColor(Color.gray);
  20. g.fillRect(125,60,61,27);
  21.  
  22. int thickness = 5;
  23. g.setColor(Color.red);
  24. for (int i = 0; i < thickness; i++)
  25. g.draw3DRect(63 - i, 60 - i, 61 2 i, 27 2 i, true);
  26.  
  27. }
  28.  
  29. public static void main(String[] args) {
  30. JFrame frame = new JFrame();
  31. frame.setTitle("My Java program");
  32. frame.setSize(1000, 200);
  33. frame.addWindowListener(new WindowAdapter() {
  34. public void windowClosing(WindowEvent e) {
  35. System.exit(0);
  36. }
  37. });
  38. Container contentPane = frame.getContentPane();
  39. contentPane.add(new Myprogram());
  40.  
  41. frame.show();
  42. }
  43.  
  44. }
May 6 '09 #1
20 3742
r035198x
13,262 MVP
Encapsulate all that logic (all the rules) into a nice class. The class represents a line from the text file. Here is an implementation of the color rules

Expand|Select|Wrap|Line Numbers
  1. class MyClass {
  2.     String line;
  3.  
  4.     MyClass(String lineFromFile) {
  5.         line = lineFromFile;
  6.     }
  7.  
  8.     public Color getColor() {
  9.         if (line.contains("andrew")) {
  10.             return Color.BLACK;
  11.         } else if (line.contains("john")) {
  12.             return Color.GRAY;
  13.         } else {
  14.             //what should you return here?
  15.         }
  16.     }
  17.  
  18. }
  19.  
May 6 '09 #2
cowboyrocks2009
17 New Member
Good idea :)

Thanks
cowboy
May 6 '09 #3
cowboyrocks2009
17 New Member
Hi can anybody help me to correct errors in this code. I have written where I am having problems inside the code. I have reached this far doing this code:-

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.awt.*;
  3. import javax.swing.*;
  4. import java.awt.Color;
  5. import javax.swing.JFrame;
  6. import java.util.ArrayList;
  7. import java.io.BufferedReader;
  8. import java.util.HashMap;
  9. import  java.awt.geom.Rectangle2D;
  10.  
  11.  
  12. public class myProgram extends JPanel {
  13.  
  14.  private ArrayList<LineInfo> lines;
  15.  private HashMap<String,Color>  hm = new HashMap<String,Color>();
  16.  private final String fileName = "file.txt";
  17.  
  18.  public myProgram(){
  19.      lines = new ArrayList<LineInfo>();
  20.      this.setPreferredSize(new Dimension(400,400));
  21.      JFrame frame = new JFrame("FillRect");
  22.      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  23.      frame.pack();
  24.      frame.setVisible(true);
  25.  }
  26.  public void populateHashMap(){
  27.      Color red = Color.RED;
  28.      Color blue = Color.BLUE;
  29.      hm.put("Andrew",red);
  30.      hm.put("david",blue);
  31.      //hm.put("john",Color.Black);
  32.      //hm.put("peter",Color.White);
  33.      //hm.put("harry",Color.Gray);
  34.  }
  35.  
  36.  @Override
  37.  public void paintComponent(Graphics g) {
  38.     super.paintComponent(g);
  39.     Graphics2D g2d = (Graphics2D) g;
  40.     g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  41.     for(int i = 0;i<lines.size();i++){
  42.            g2d.setColor(lines.get(i).getColor());
  43.            g2d.fill(lines.get(i).getRect());
  44.     }
  45.  
  46.  }
  47.  
  48.  public void readFile()throws Exception {    
  49.       String n = null;
  50.     try{
  51.             BufferedReader fh = new BufferedReader(new FileReader(fileName));    
  52.             while(true){
  53.                n = fh.readLine();
  54.                if(n == null){
  55.                   break;
  56.                }else{
  57.                     System.out.println(n); //testing
  58.                     String[] args = n.split("\t");
  59.                     //Here I want to create new Rectangle here called say tempRect
  60.                     //get color by using Color color = (Color)hm.get(args[x]); where x is the name index
  61.                     //create bew LineInfo object LineInfo tempLineInfo = new LineInfo(tempRect,color);
  62.                     //add to arraylist  lines.add(tempLineInfo);
  63.              }//end of else
  64.           }//end while
  65.           fh.close();
  66.        }catch (FileNotFoundException e1) {
  67.             System.err.println("File not found: ");
  68.        }
  69.    }
  70.  
  71.  
  72.   public static void main (String[] args){
  73.     myProgram test = new myProgram();
  74.     test.populateHashMap();
  75.     try{
  76.         test.readFile();
  77.     }catch(Exception e){
  78.         System.err.println(e);
  79.     }
  80.   }
  81. }//end of main class
  82.  
  83.  
  84.  
  85. class LineInfo{
  86.    private Rectangle2D.Double rect;
  87.    private Color color;
  88.    public LineInfo(Rectangle2D.Double rect, Color c){
  89.        this.rect = rect;
  90.        this.color = c;
  91.    }
  92.    public Rectangle2D getRect(){
  93.        return rect;
  94.    }
  95.    public Color getColor(){
  96.        return color;
  97.    }
  98. }//end of class
  99.  
My input file looks like this:-

Expand|Select|Wrap|Line Numbers
  1. 1    p    36.33b    0    11    1    1150001    austin    0.0    5.91    2    0.0019
  2. 1    p    36.33a    12    24    1150002    2300000    harry    5.91    8.75    2    0.0019
  3. 1    p    36.32c    25    36    2300000    3300000    austin    8.75    11.19    0    0
  4. 1    p    36.32b    37    49    3300001    4300000    austin    11.19    13.59    3    0.00285
  5. 1    p    36.32a    50    61    4300001    5300000    peter    13.59    15.97    10    0.00951
  6. 1    p    36.31b    62    72    5300000    6200000    peter    15.97    18.07    5    0.00476
  7. 1    p    36.31a    73    82    6200001    7100000    harry    18.07    20.15    8    0.00761
  8. 1    p    36.23b    83    93    7100000    8050000    austin    20.15    22.32    8    0.00761
  9. 1    p    36.23a    94    104    8050001    9000000    john    22.32    24.46    4    0.00381
  10. 1    p    36.22d    105    125    9000000    9825000    harry    24.46    26.3    5    0.00476
  11.  
May 11 '09 #4
r035198x
13,262 MVP
What errors are you getting? Where are you creating the LineInfo objects and adding them to the ArrayList?
May 11 '09 #5
cowboyrocks2009
17 New Member
This is my modified code. Please find the error message below:-

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.awt.*;
  3. import javax.swing.*;
  4. import java.awt.Color;
  5. import javax.swing.JFrame;
  6. import java.util.ArrayList;
  7. import java.io.BufferedReader;
  8. import java.util.HashMap;
  9. import  java.awt.geom.Rectangle2D;
  10. import java.awt.Rectangle;
  11.  
  12.  
  13. public class kalia extends JPanel {
  14.  
  15.  private ArrayList<LineInfo> lines;
  16.  private HashMap<String,Color>  hm = new HashMap<String,Color>();
  17.  private final String fileName = "C:/InputFile.txt";
  18.  
  19.  public kalia(){
  20.      lines = new ArrayList<LineInfo>();
  21.      this.setPreferredSize(new Dimension(1000,400));
  22.      JFrame frame = new JFrame("FillRect");
  23.      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  24.      frame.pack();
  25.      frame.setVisible(true);
  26.  }
  27.  public void populateHashMap(){
  28.     Color red = Color.RED;
  29.      Color blue = Color.BLUE;
  30.      hm.put("Andrew",red);
  31.      hm.put("david",blue);
  32.      //hm.put("john",Color.Black);
  33.      //hm.put("peter",Color.White);
  34.      //hm.put("harry",Color.Gray);
  35.  }
  36.  
  37.  @Override
  38.  public void paintComponent(Graphics g) {
  39.     super.paintComponent(g);
  40.     Graphics2D g2d = (Graphics2D) g;
  41.     g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  42.     for(int i = 0;i<lines.size();i++){
  43.            g2d.setColor(lines.get(i).getColor()); 
  44.            g2d.fill(lines.get(i).getRect());
  45.     }
  46.  
  47.  }
  48.  
  49.  public void readFile()throws Exception {    
  50.       String n = null;
  51.       ArrayList<LineInfo> rects = new ArrayList<LineInfo>();
  52.     try{
  53.             BufferedReader fh = new BufferedReader(new FileReader(fileName));    
  54.             while(true){
  55.                n = fh.readLine();
  56.                if(n == null){
  57.                   break;
  58.                }else{
  59.                     System.out.println(n); //testing 
  60.                     String f[]  = n.split("\t");
  61.  
  62.                         int iscntop = Integer.parseInt(f[3]);
  63.                         int iscnbot = Integer.parseInt(f[4]);             
  64.  
  65.                         int width = iscntop - iscnbot;
  66.  
  67.                         Rectangle tempRect = new Rectangle(iscntop,60,width,27);
  68.                         Color color = (Color)hm.get(n); //where x is the name index
  69.                         LineInfo tempLineInfo = new LineInfo(tempRect,color);
  70.                         lines.add(tempLineInfo);
  71.              }//end of else
  72.           }//end while
  73.           fh.close();
  74.        }catch (FileNotFoundException e1) {
  75.             System.err.println("File not found: ");
  76.        }
  77.    }
  78.  
  79.  
  80.   public static void main (String[] args){
  81.     kalia test = new kalia();
  82.     test.populateHashMap();
  83.     try{
  84.         test.readFile();
  85.     }catch(Exception e){
  86.         System.err.println(e);
  87.     }
  88.   }
  89. }//end of main class
  90.  
  91.  
  92.  
  93. class LineInfo{
  94.    private Rectangle2D.Double rect;
  95.    private Color color;
  96.    public LineInfo(Rectangle2D.Double rect, Color c){
  97.        this.rect = rect;
  98.        this.color = c;
  99.    } 
  100.    public Rectangle2D getRect(){
  101.        return rect;
  102.    }
  103.    public Color getColor(){
  104.        return color;
  105.    }
  106. }//end of class
Error message is this :-
Expand|Select|Wrap|Line Numbers
  1. symbol  : constructor LineInfo(java.awt.Rectangle,java.awt.Color)
  2. location: class mypackage.LineInfo
  3.                         LineInfo tempLineInfo = new LineInfo(tempRect,color);
  4. 1 error
  5. BUILD FAILED (total time: 1 second)
May 11 '09 #6
JosAH
11,448 Recognized Expert MVP
Read the error message: you don't have a constructor in your LineInfo class that takes a Rectangle and a Color as parameters.

kind regards,

Jos
May 12 '09 #7
cowboyrocks2009
17 New Member
I have written another program which is doing almost the same thing. It reads the drawrects() method but when it reaches the 2nd and 3rd method it shows null , null. I modified the input file by replacing colours instead on names ..andrew etc... Why is this null coming while reading 2nd and 3rd method. If you will run the program you will come to know what is happening.

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.BufferedReader;
  7. import java.util.List;
  8. import java.awt.*;
  9. import javax.swing.*;
  10. import java.awt.Color;
  11. import java.awt.event.WindowAdapter;
  12. import java.awt.event.WindowEvent;
  13. import javax.swing.JFrame;
  14. /**
  15.  *
  16.  * @author admin
  17.  */
  18.  class cows {
  19.     private ArrayList<cows> rects;
  20.     private ArrayList<cows> colors;
  21.     private ArrayList<cows> fills;
  22.  
  23.    public ArrayList<cows> drawrects() {
  24.          String n = null;
  25.     try{
  26.             BufferedReader fh = new BufferedReader(new FileReader("InputFile.txt"));    
  27.             while(true){
  28.                n = fh.readLine();
  29.                if(n == null){
  30.                   break;
  31.                }else{
  32.                   String f[] = n.split("\t");
  33.  
  34.                         int iscntop = Integer.parseInt(f[3]);
  35.                         int iscnbot = Integer.parseInt(f[4]);
  36.  
  37.                         long width = iscntop - iscnbot;
  38.  
  39.                         List list = new ArrayList(Arrays.asList("g.drawRect("+f[3]+","+"60"+","+width+","+"27"+")"));
  40.  
  41.                        // LinkedHashMap hm = new LinkedHashMap();
  42.  
  43.                       //  System.out.println(list);
  44.                       //  System.out.println(list);
  45.  
  46.  
  47.    }
  48.  
  49.           }//end while
  50.           fh.close();
  51.        } catch (FileNotFoundException e) {
  52.             e.printStackTrace();
  53.         } catch (IOException e2) {
  54.             e2.printStackTrace();
  55.          } 
  56. return rects;
  57.  
  58.    public ArrayList<cows> fillrects() {
  59.          String n = null;
  60.     try{
  61.             BufferedReader fh = new BufferedReader(new FileReader("InputFile.txt"));    
  62.             while(true){
  63.                n = fh.readLine();
  64.                if(n == null){
  65.                   break;
  66.                }else{
  67.                   String f[] = n.split("\t");
  68.  
  69.                         int iscntop = Integer.parseInt(f[3]);
  70.                         int iscnbot = Integer.parseInt(f[4]);
  71.  
  72.                         Integer width = iscntop - iscnbot;
  73.  
  74.  
  75.                         List list = new ArrayList(Arrays.asList("g.fillRect("+f[3]+","+"60"+","+width+","+"27"+")"));
  76.  
  77.                         //System.out.println(list);
  78.  
  79.  
  80.    }
  81.  
  82.           }//end while
  83.           fh.close();
  84.        } catch (FileNotFoundException e) {
  85.             e.printStackTrace();
  86.         } catch (IOException e2) {
  87.             e2.printStackTrace();
  88.          } 
  89. return fills;
  90. }
  91.    public ArrayList<cows> colorrects() {
  92.          String n;
  93.     try{
  94.             BufferedReader fh = new BufferedReader(new FileReader("InputFile.txt"));    
  95.             while(true){
  96.                n = fh.readLine();
  97.                if(n == null){
  98.                   break;
  99.                }else{
  100.                   String f[] = n.split("\t");
  101.  
  102.                         int iscntop = Integer.parseInt(f[3]);
  103.                         int iscnbot = Integer.parseInt(f[4]);
  104.  
  105.                         Integer width = iscntop - iscnbot;
  106.  
  107.                         List list = new ArrayList(Arrays.asList("g.setColor"+"("+"Color."+f[7]+")"));
  108.  
  109.                       //  System.out.println(list);
  110.  
  111.  
  112.    }
  113.  
  114.           }//end while
  115.           fh.close();
  116.        } catch (FileNotFoundException e) {
  117.             e.printStackTrace();
  118.         } catch (IOException e2) {
  119.             e2.printStackTrace();
  120.          } 
  121. return colors;
  122. }
  123.  
  124. }
  125.  
  126. public class wow extends JPanel{
  127.  
  128.  public void paintComponent(Graphics g) {
  129.     super.paintComponent(g);
  130.     cows xman = new cows();
  131.     System.out.println(xman.drawrects());
  132.     System.out.println(xman.fillrects());
  133.     System.out.println(xman.colorrects());
  134.                                         }
  135.  
  136.     public static void main(String[] args) {
  137.             JFrame frame = new JFrame();
  138.     frame.setTitle("My Rects");
  139.     frame.setSize(1000, 200);
  140.     frame.addWindowListener(new WindowAdapter() {
  141.       public void windowClosing(WindowEvent e) {
  142.         System.exit(0);
  143.       }
  144.     });
  145.     Container contentPane = frame.getContentPane();
  146.     contentPane.add(new wow());
  147.  
  148.     frame.show();
  149.   }
  150.  
  151.     }
Here is my sample input file:-
Expand|Select|Wrap|Line Numbers
  1. 1    p    36.33b    0    50    1    1150001    black    0.0    5.91    2    0.0019
  2. 1    p    36.33a    51    100    1150002    2300000    red    5.91    8.75    2    0.0019
  3. 1    p    36.32c    100    148    2300000    3300000    white    8.75    11.19    0    0
  4. 1    p    36.32b    149    196    3300001    4300000    gray    11.19    13.59    3    0.00285
  5. 1    p    36.32a    197    244    4300001    5300000    black    13.59    15.97    10    0.00951
  6. 1    p    36.31b    244    294    5300000    6200000    gray    15.97    18.07    5    0.00476
  7. 1    p    36.31a    295    344    6200001    7100000    blue    18.07    20.15    8    0.00761
  8. 1    p    36.23b    344    402    7100000    8050000    cyan    20.15    22.32    8    0.00761
  9. 1    p    36.23a    403    459    8050001    9000000    yellow    22.32    24.46    4    0.00381
  10.  
  11.  
I need help urgently :(
Thanks in advance
Cowboy
May 16 '09 #8
JosAH
11,448 Recognized Expert MVP
This is the basic structure of your cows class:

Expand|Select|Wrap|Line Numbers
  1.  class cows {
  2.     private ArrayList<cows> rects;
  3.     private ArrayList<cows> colors;
  4.     private ArrayList<cows> fills;
  5.  
  6.    public ArrayList<cows> drawrects() {
  7.    // nothing here assigns an ArrayList to variable 'rects'
  8.    return rects;
  9.    } 
  10.  
  11.    public ArrayList<cows> fillrects() {
  12.    // nothing here assigns an ArrayList to variable 'fills'
  13.    return fills;
  14.    }
  15.  
  16.    public ArrayList<cows> colorrects() {
  17.    // nothing here assigns an ArrayList to variable 'colors'
  18.    return colors;
  19.    }
  20. }
  21.  
IMHO, your code is a bit of a mess. Please design first before you want to implement anything.

kind regards,

Jos
May 16 '09 #9
cowboyrocks2009
17 New Member
I have corrected some of my mistakes which happened while pasting into ur forum and changing names of some methods. Anyway here is the corrected code. Can you now help me to get it right. I need help badly.

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.BufferedReader;
  7. import java.util.List;
  8. import java.awt.*;
  9. import javax.swing.*;
  10. import java.awt.Color;
  11. import java.awt.event.WindowAdapter;
  12. import java.awt.event.WindowEvent;
  13. import javax.swing.JFrame;
  14. /**
  15.  *
  16.  * @author admin
  17.  */
  18.  class cows {
  19.     private ArrayList<cows> rects;
  20.     private ArrayList<cows> colors;
  21.     private ArrayList<cows> fills;
  22.  
  23.    public ArrayList<cows> drawrects() {
  24.          String n = null;
  25.     try{
  26.             BufferedReader fh = new BufferedReader(new FileReader("InputFile.txt"));    
  27.             while(true){
  28.                n = fh.readLine();
  29.                if(n == null){
  30.                   break;
  31.                }else{
  32.                   String f[] = n.split("\t");
  33.  
  34.                         String band = f[2];
  35.                         int iscntop = Integer.parseInt(f[3]);
  36.                         int iscnbot = Integer.parseInt(f[4]);
  37.  
  38.                         long width = iscntop - iscnbot;
  39.  
  40.                         List rects = new ArrayList(Arrays.asList("g.drawRect("+f[3]+","+"60"+","+width+","+"27"+")"));
  41.  
  42.  
  43.                         System.out.println(rects);
  44.  
  45.  
  46.    }
  47.  
  48.           }//end while
  49.           fh.close();
  50.        } catch (FileNotFoundException e) {
  51.             e.printStackTrace();
  52.         } catch (IOException e2) {
  53.             e2.printStackTrace();
  54.          } 
  55. return rects;
  56.  
  57.    public ArrayList<cows> fillrects() {
  58.          String n = null;
  59.     try{
  60.             BufferedReader fh = new BufferedReader(new FileReader("InputFile.txt"));    
  61.             while(true){
  62.                n = fh.readLine();
  63.                if(n == null){
  64.                   break;
  65.                }else{
  66.                   String f[] = n.split("\t");
  67.  
  68.                         int iscntop = Integer.parseInt(f[3]);
  69.                         int iscnbot = Integer.parseInt(f[4]);
  70.  
  71.  
  72.                         Integer width = iscntop - iscnbot;
  73.  
  74.  
  75.                         List fills = new ArrayList(Arrays.asList("g.fillRect("+f[3]+","+"60"+","+width+","+"27"+")"));
  76.  
  77.  
  78.    }
  79.  
  80.           }//end while
  81.           fh.close();
  82.        } catch (FileNotFoundException e) {
  83.             e.printStackTrace();
  84.         } catch (IOException e2) {
  85.             e2.printStackTrace();
  86.          } 
  87. return fills;
  88. }
  89.  
  90.    public ArrayList<cows> colorrects() {
  91.          String n;
  92.     try{
  93.             BufferedReader fh = new BufferedReader(new FileReader("InputFile.txt"));    
  94.             while(true){
  95.                n = fh.readLine();
  96.                if(n == null){
  97.                   break;
  98.                }else{
  99.                   String f[] = n.split("\t");
  100.  
  101.                         int iscntop = Integer.parseInt(f[3]);
  102.                         int iscnbot = Integer.parseInt(f[4]);
  103.  
  104.                         Integer width = iscntop - iscnbot;
  105.  
  106.                         List colors = new ArrayList(Arrays.asList("g.setColor"+"("+"Color."+f[7]+")"));
  107.  
  108.  
  109.  
  110.    }
  111.  
  112.           }//end while
  113.           fh.close();
  114.        } catch (FileNotFoundException e) {
  115.             e.printStackTrace();
  116.         } catch (IOException e2) {
  117.             e2.printStackTrace();
  118.          } 
  119. return colors;
  120. }
  121.  
  122. }
  123.  
  124. public class wow extends JPanel{
  125.  
  126.  public void paintComponent(Graphics g) {
  127.     super.paintComponent(g);
  128.     cows xman = new cows();
  129.     xman.drawrects(); // here I am trying to draw rectangles by calling values from cow class through method drawrects()
  130.     xman.fillrects();
  131.     xman.colorrects();
  132.                                         }
  133.  
  134.     public static void main(String[] args) {
  135.             JFrame frame = new JFrame();
  136.     frame.setTitle("Plot Rects");
  137.     frame.setSize(1000, 200);
  138.     frame.addWindowListener(new WindowAdapter() {
  139.       public void windowClosing(WindowEvent e) {
  140.         System.exit(0);
  141.       }
  142.     });
  143.     Container contentPane = frame.getContentPane();
  144.     contentPane.add(new wow());
  145.  
  146.     frame.show();
  147.   }
  148.  
  149.     }
  150.  
Thanks in advance
Cowboy
May 16 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2901
by: Darsant | last post by:
I'm currently reading 1-n number of binary files, each with 3 different arrays of floats containing about 10,000 values a piece for a total of about 30,000 values per file. I'm looking for a way to load them all into memory. I've tried using vector pushback with reserving, but it was horribly slow. The current method I am using is upon opening the file and reading the number of values, resizing the vectors (I have 3, one for each data...
1
1719
by: Szaki | last post by:
I use a BulkLoad to import file.xml to my base MS Server 2000. To import this xml file I need schema file. Mayby you know how to do this file mechanicy f.g. mayby somebody have some script in .net who generate this schema. for any help Thanks ======== My xml file ================================= <ROOT> <Customers> <CustomerId>5555</CustomerId>
7
2627
by: sreenulanka | last post by:
please help me in my forum i have labels and textareas .iwant to add textarea components dyanamically when i am clicking the button.please help me import java.awt.*; import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; import java.io.*; import java.applet.*;
7
3747
oll3i
by: oll3i | last post by:
i want to change the values in two columns one colum is a combobox and the secons column is editable too i want to get the value of that second column and the value of combobox and sent that to another application i have setValueAt(Object value,int row, int col) but it works only for combobox when i enter some data in the second editable column the value i entered disappears rows are a list data = new...
1
2919
by: stevedub | last post by:
I am having some trouble configuring my array to read from a sequential file, and then calling on that to fill an array of interests. I think I have the class set up to read the file, but when I run my program the rates array does not get the information. I think my problem is where I am actuall calling the array index, but I am not sure how to do this. Here is my code: /* * MortFrame.java * * Created on February 24, 2008, 7:28 PM */...
8
3114
by: eddiewould | last post by:
Hi, I want to write a custom widget which will act similarly to a JPanel (i.e it can contain other Components), but semantically it's not a kind of JPanel so it shouldn't extend from it. Here is some sample code showing what I'm trying to achieve: Effectively I expect to see a JLabel with the message "This is a test" as well as a JButton "foo". What am I doing wrong? Is this possible? Also, I am aware it would be easier to just extend...
1
2787
by: Akino877 | last post by:
Hello, I have a question regarding Java and Swing programming I wonder if I could ask the forum for some help. I have a JPanel that has a couple of radio buttons and an "OK/Next" button on it. When a radio button wass selected and "OK/Next" was clicked on, I was able to write some code inside the "ActionPerformed" method to verify that the radio button was selected as intended. But that was only a quick test to see that things worked. ...
4
7896
by: lilyumestar | last post by:
I have project I have to do for class. We have to write 4 different .java files. Project2.java HouseGUI.java House.java HouseSorting.java I already finish House.java and I need to work on both the Project2.java and HouseGUI.java Here are the requirements for those two. The GUI Create a class called HouseGUI which extends JFrame. It should display two text areas (JTextArea) in a grid layout (1 row, 2 columns). Your main program,...
1
4211
AnuSumesh
by: AnuSumesh | last post by:
Hi, I want to read the text property of XML file. My xml file is as follows: <?xml version="1.0"?> <Domain_Credentials> <User> anu </User>
0
8590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8527
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8781
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5806
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4321
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2961
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2214
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1947
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.