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:- - 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);
-
-
}
-
}
-
Thanks
4 2528
What specific problems are you having with your code?
Hi... Actually I donno howto make my for loop work in this case. I am taking values from the text file. Can you give some clues.
Thanks
Do you have another handle 'cowboyrocks2009'?
kind regards,
Jos
No why ? I was curious to know how for loop will work in this case.
Thanks
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rupam |
last post by:
The following code segment is the beginning of a user-defined
paintComponent method:
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D0 g;
}
|
by: Ideasman |
last post by:
Hi I have a made a script that process normals for a flat shaded 3D mesh's.
It compares every vert with every other vert to look for verts that can
share normals and It takes ages.
I'm not...
|
by: Keith |
last post by:
Good Afternoon,
New to .Net. I am trying to pass date/time values to a MS Access query depending on what value is selected from a dropdown list box (January, February, etc). I have declared...
|
by: Karthik |
last post by:
I am trying to read Http request body values NOT form values
The content type is text/xml and its POST
I am posting data from Infopath to an asp.net page.
In ASP it works by just writing...
|
by: DH |
last post by:
Hi,
I'm trying to strip the html and other useless junk from a html page..
Id like to create something like an automated text editor, where it
takes the keywords from a txt file and removes them...
|
by: so many sites so little time |
last post by:
this time i am going to use the scripts from the book and just change
the names to match what i am trying to do now i just got an error that
i know shouldnt be an error i think. this is the error:...
|
by: redgrL86 |
last post by:
Hi,
I am working on an XSL stylesheet and I have a loop within a loop where I need to compare element values from the inside loop to values from the outer loop (see bolded line in XSL below). The...
|
by: Catalyst159 |
last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows:
Part A: Maximum FAR and Floor Area:
Part B: Gross Floor Area of...
|
by: Debadatta Mishra |
last post by:
Introduction
In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |