Hi,
I want to read values from a text files from specified fields and use them as values to fill my methods inside the paintComponent( ) method. I am using for loop to do that but not able to do it properly. Can somebody give me a good example code howto do it ??
Here is extract of my code below:-
Thanks
I want to read values from a text files from specified fields and use them as values to fill my methods inside the paintComponent( ) method. I am using for loop to do that but not able to do it properly. Can somebody give me a good example code howto do it ??
Here is extract of my code below:-
Code:
public class testing extends JPanel{
private ArrayList<Myclass> lines;
private HashMap<String,Color> hm = new HashMap<String,Color>();
private int firstvalue;
private int width;
private String color;
private int f[];
public void drawrects() {
String n = null;
try{
BufferedReader fh = new BufferedReader(new FileReader("myinput.txt"));
while(true){
n = fh.readLine();
if(n == null){
break;
}else{
String f[] = n.split("\t");
int firstvalue = Integer.parseInt(f[3]);
int width = Integer.parseInt(f[4]);
Color color = (Color)hm.get(f[7]);
Myclass lineinformation = new Myclass(color);
Myclass lineinformation = new Myclass(color);
lines.add(lineinformation);
}
}
fh.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Myclass myobject = new Myclass();
int x = myobject.firstvalue;
int y = 60;
int w = myobject.width;
int z = 27;
g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
for(int i=0; i<Myclass.f.length; i++){
GradientPaint gpi = new GradientPaint(0, 0, lines.get(i).getColor(), 0, 20, Color.white, true);
g2d.drawRect(x, 60, w, 27);
g2d.setColor(gpi);
g2d.fillRect(x, 60, w, 27);
}
}
Comment