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:-
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:-
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:-
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:-
Code:
g.drawRect(0,60,62,27); g.setColor(Color.black); g.fillRect(0,60,62,27); g.drawRect(63,60,61,27); g.setColor(Color.gray); g.fillRect(63,60,61,27);
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:-
Code:
int thickness = 5; g.setColor(Color.red); for (int i = 0; i < thickness; i++) g.draw3DRect(63 - i, 60 - i, 61 2 i, 27 2 i, true);
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:-
Code:
import java.awt.; import javax.swing.; import java.awt.Color; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; public class Myprogram extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); g.drawRect(0,60,62,27); g.setColor(Color.black); g.fillRect(0,60,62,27); g.drawRect(63,60,61,27); g.setColor(Color.gray); g.fillRect(63,60,61,27); g.drawRect(125,60,61,27); g.setColor(Color.gray); g.fillRect(125,60,61,27); int thickness = 5; g.setColor(Color.red); for (int i = 0; i < thickness; i++) g.draw3DRect(63 - i, 60 - i, 61 2 i, 27 2 i, true); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle("My Java program"); frame.setSize(1000, 200); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); Container contentPane = frame.getContentPane(); contentPane.add(new Myprogram()); frame.show(); } }
Comment