Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 26

Thread: reading and witing to txt file

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Unhappy reading and witing to txt file

    i have created a gui interface with 4-5 textfields ...
    In txt file i have for example set to default
    number1 100
    number2 101
    number3 10
    i have to import numbers to textfield
    100 to textfield1
    101 to textfield2
    10 to textfiled3
    and after reading default numbers, they must be shown in textfileds, which is obvious
    So now i have numbers in my filelds automaticly read as default, and for example i change textfileld2 to 200
    so now i have in my textfields in gui set like:
    textfield1 set to 100
    textfield2 set to 200
    textfield3 set to 10
    and i have to save that changed numbers in txt file back, but i have to save it below defaults, so defaults can be read if i run another instance of program, and i must have option to read changed numbers too.
    ---- when i run aplication, it will automaticly read from default and they will be shown in textfields, and when i change numbers in txt fields, i have to save them as new numbers in same file, without rewriting defaults.
    Last edited by nautilusz; January 19th, 2012 at 04:26 PM.


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: reading and witing to txt file

    Okay best of luck.

    If you have a question don't be too shy to ask, as although I can read minds, the rest of the Java Programming Forum community are lacking in in the psychic department .
    First port of call would probably be the following tutorial:
    Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)

    or alternatively, google will have a plethora of examples
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. The Following User Says Thank You to newbie For This Useful Post:

    nautilusz (January 20th, 2012)

  4. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: reading and witing to txt file

    Post what you've tried, or a specific question related to the problem and you will greatly increase your chances of receiving help.

  5. The Following User Says Thank You to copeg For This Useful Post:

    nautilusz (January 20th, 2012)

  6. #4
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: reading and witing to txt file

    ok, thx
    i will try something and post progress
    First problem.
    i know how to read whole txt, but how to read single item form line
    e.g.
    my txt file has 30 lines
    line1 100
    line2 200
    ....
    line30 255

    how do i read "line2 200",and add it to my textfield, so i have in textfield written number "200".

  7. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: reading and witing to txt file

    how to read single item form line
    If the lines have tokens/words separated by spaces, you could use the String class's split method to create an array with all the tokens.

  8. The Following User Says Thank You to Norm For This Useful Post:

    nautilusz (January 20th, 2012)

  9. #6
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: reading and witing to txt file

    it's not the problem to pick number from the string. i could use it by simple reader, i was planing to use something like this

    import java.util.*;
    import java.io.*;
     
    public class java_read_txt {
     
        private Scanner x;
     
        public void openFile(){
            try{
                x = new Scanner(new File("abc.txt"));
            }
            catch(Exception e){
                System.out.println("can't read");
            }
        }
        public void readFile(){
            while(x.hasNext()){
                String a = x.next();    //string a would be first element "label"
                String b = x.next();    //string b would be second element "number"
            }
        }
     
        public void closeFile(){
            x.close();
        }
    }

    but this code will also go through all txt document, and use all strings
    problem is to pick a single line, e.g. 24. line in the txt, and from that line use number

  10. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: reading and witing to txt file

    problem is to pick a single line
    Please explain in more detail.
    Are you trying to pick a line by its position in the file? In that case you need to read over all the lines that precede the desired line until you get to the line that you want.

  11. The Following User Says Thank You to Norm For This Useful Post:

    nautilusz (January 20th, 2012)

  12. #8
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: reading and witing to txt file

    The point is this.
    gdf.JPG
    On the picture, you can see what i have to do.
    Numbers have to be written in txt file, and automaticly loaded when i open that instance of program.
    When numbers are loaded, i can change them, and when i do that, and i click on button "Prihvati"
    all numbers have to be saved back to txt file, but without overwriting the default ones because they need to be the same if i run another instance of program.
    I have already written a gui, and everything on interface, now i need to connect my gui to a txt file.

  13. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: reading and witing to txt file

    Have you solved your problem?
    Or do you have more questions or problems?
    Please explain what you are having problems with.

  14. #10
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: reading and witing to txt file

    I just posted my problem post earlier.
    I have no clue how to read numbers from same txt file, to different textfields, and each number is on different line in txt. e.g. How to specify that in first textfield goes number written on 10th line in txt file, and on seccond textfield goes number written on 12th line in the txt file.

  15. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: reading and witing to txt file

    how to read numbers from same txt file
    Can you read the lines of the text file, one after the the other?
    Can you parse the data on each line into separate tokens using split?
    Can you convert a String to a number using an Integer class method?

    Can you count the lines as you read them from a file so you know which line is the 10th line?

    Which of the above are you having problems with?

  16. #12
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: reading and witing to txt file

    I haven't worked before with I/O from txtfile, so i have problem with everything. I hate working with lines, but i have to. If you know code that will help me with my program that would be great, if you don't can you tell me how to do something like that. I suppose i need to read line by line, until i get to the wanted line, and when i get to the wanted one then i need to parse data on that line using split so i can use just seccond part of string,which is my wanted number, and then convert that string number into integer.
    I'm going crazy

  17. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: reading and witing to txt file

    i need to read line by line, until i get to the wanted line, and when i get to the wanted one then i need to parse data on that line using split so i can use just seccond part of string,which is my wanted number, and then convert that string number into integer.
    Yes that sounds like the way to do it.

    You can use the Scanner class's nextLine() method to read the lines from the file.

  18. #14
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: reading and witing to txt file

    ok, i'll try something tonight, is there a way to make a class which will be doing all of this, and when i call the class i give to it argument which line to use, because i will be needing to call that class for every textfield.

  19. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: reading and witing to txt file

    Yes you could create a method (not a class) that you can call with the line number you want it to read and return.

  20. #16
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: reading and witing to txt file

    change of plans ... i decided it is easier to use json not plain txt.
    import java.io.FileReader;
    import java.io.IOException;
    import org.json.simple.JSONObject;
    import org.json.simple.parser.JSONParser;
    import org.json.simple.parser.ParseException;
     
    public class java_read_txt {
         public static void main(String[] args) throws ParseException {
     
    	JSONParser parser = new JSONParser();
     
    	try {
     
    		Object obj = parser.parse(new FileReader("c:\\mreza3.json"));
     
    		JSONObject jsonObject = (JSONObject) obj;
     
    		long age = (Long) jsonObject.get("LinkMTTR");
    		System.out.println(age);
     
    	} catch (IOException e) {
    		e.printStackTrace();
     
    	}
     
      }
     
    }

    txt file (json file), is made like this,
    {
    "LinkLambda" : 100,
    "LinkMTTR" : 10,
    "LinkRaspolozivost" : 0

    "MuxDemux" : {
    "MuxDemuxLambda" : 100,
    "MuxDemuxMTTR" : 10,
    "MuxDemuxBrojKartica" : 10,
    "MuxDemuxRaspolozivost" : 0
    }
    so when i run my reader it writes on console number "10" ... so i got what i wanted, at least part of it
    My textfield is in another Jframe, so now i need to call my reader class and make it not to write to console but to write into my textfield.
    Any suggestions how to do that.
    Last edited by nautilusz; January 21st, 2012 at 08:09 PM.

  21. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: reading and witing to txt file

    i need to call my reader class and make it not to write to console but to write into my textfield.
    You could pass a reference to the textfield to the method that is reading the data and it could use that reference to put a String into the textfield.

  22. #18
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: reading and witing to txt file

    can you write me a code, e.g. this is my textfield

    textField = new JTextField();
    textField.setBounds(142, 9, 127, 20);
    Link_P.add(textField);
    textField.setColumns(10);

    and the frame where textfield is, is called f_elementi.java ... and reader class is post upper

  23. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: reading and witing to txt file

    When you call the method that is reading/getting the String pass the variable: textField as a parameter.
    theReadMethod(textField); // pass textField to the method
    In the method that is doing the reading, the method should use the JTextField class's set... method to set the contents of the textfield to the String that was read.

    Remember: you call methods not classes.

  24. #20
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: reading and witing to txt file

    I don't get it.
    because my reading class at the end creates variable "age", and that variable has to be written into textfiled which
    is created on my main class.
    so i suppose i need add after
    textField = new JTextField();
    textField.setBounds(142, 9, 127, 20);
    Link_P.add(textField);
    textField.setColumns(10);
    ...
    textField.setText(xxx); // on the xxx i should call my variable "age" somehow
    earlyer i create
    java_read_txt text1 = new java_read_txt(); //java_read_txt is the name of my reading class

    I look stupid now, don't I? .. maybe because it's 3AM

  25. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: reading and witing to txt file

    because my reading class at the end creates variable "age"
    Its done in a method. You call methods to do some job or task.
    One or more methods are contained in a class.

  26. #22
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: reading and witing to txt file

    ok, it's done in a method. when i call it it will do the reading from the file, and create my variable.
    i still don't know how to connect that variable with a textfield. any concrete suggestion, or code so i could learn to do that.
    if it helps :
    this is my jframe code, where are my textfields
    import java.awt.EventQueue;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.Font;
    import java.awt.Color;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.JCheckBox;
    import javax.swing.JScrollPane;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.GroupLayout;
    import javax.swing.GroupLayout.Alignment;
    import javax.swing.SwingConstants;
    import java.awt.Rectangle;
    import javax.swing.LayoutStyle.ComponentPlacement;
     
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
     
     
    public class f_elementi extends JFrame {
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    	private JTextField textField;
    	private JTextField textField_1;
    	private JTextField textField_2;
    	private JTextField textField_3;
    	private JTextField textField_4;
    	private JTextField raspolozivost_txt;
    	private JTextField textField_14;
    	private JTextField textField_5;
    	private JTextField textField_6;
    	private JTextField textField_7;
    	private JTextField textField_15;
    	private JTextField textField_8;
    	private JTextField textField_9;
    	private JTextField textField_10;
    	private JTextField textField_16;
    	private JTextField textField_11;
    	private JTextField textField_12;
    	private JTextField textField_13;
    	private JTextField textField_17;
    	private JTextField textField_18;
    	private JTextField textField_19;
    	private JTextField textField_20;
    	private JTextField textField_21;
    	private JTextField textField_22;
    	private JTextField textField_23;
    	private JTextField textField_24;
    	private JTextField textField_25;
    	private JTextField textField_26;
    	private JTextField textField_27;
    	private JTextField textField_28;
    	private JTextField textField_29;
    	private JTextField textField_30;
    	private JTextField textField_31;
    	private JTextField textField_32;
    	private JTextField textField_33;
    	private JTextField textField_34;
    	private JTextField textField_37;
     
     
     
    	/**
    	 * Launch the application.
    	 */
    	public static void main(String[] args) {
    		EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				try {
    					f_elementi frame = new f_elementi();
    					frame.setVisible(true);
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    			}
    		});
    	}
    	// kreiranje json readera
     
     
     
     
     
     
    	//-----------------------------------------
     
     
     
     
    	/**
    	 * Create the frame.
    	 */
    	public f_elementi() {
    		setAlwaysOnTop(true);
    		setTitle("Elementi Mreze");
    		setResizable(false);
    		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    		setBounds(100, 200, 365, 458);
    		getContentPane().setLayout(null);
    		JPanel panel = new JPanel();
    		panel.setBounds(0, 0, 349, 2000);
    		getContentPane().add(panel);
    		panel.setLayout(null);
     
    		JScrollPane scrollPane = new JScrollPane();
    		scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    		scrollPane.setBounds(0, 0, 349, 378);
    		panel.add(scrollPane);
     
    		JPanel panel_1 = new JPanel();
    		panel_1.setBounds(new Rectangle(0, 0, 349, 2000));
    		scrollPane.setViewportView(panel_1);
     
    		JPanel panel_2 = new JPanel();
     
     
    		JLabel Link_L = new JLabel("Link");
    		panel_1.add(Link_L);
    		Link_L.setForeground(new Color(0, 51, 255));
    		Link_L.setFont(new Font("SansSerif", Font.PLAIN, 13));	
    		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
    		gl_panel_1.setHorizontalGroup(
    			gl_panel_1.createParallelGroup(Alignment.LEADING)
    				.addGroup(gl_panel_1.createSequentialGroup()
    					.addGap(22)
    					.addComponent(Link_L, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
    					.addContainerGap(296, Short.MAX_VALUE))
    				.addComponent(panel_2, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
    		);
    		gl_panel_1.setVerticalGroup(
    			gl_panel_1.createParallelGroup(Alignment.LEADING)
    				.addGroup(gl_panel_1.createSequentialGroup()
    					.addGap(22)
    					.addComponent(Link_L)
    					.addPreferredGap(ComponentPlacement.RELATED, 82, Short.MAX_VALUE)
    					.addComponent(panel_2, GroupLayout.PREFERRED_SIZE, 1617, GroupLayout.PREFERRED_SIZE)
    					.addGap(70))
    		);
    		panel_2.setLayout(null);
    		panel_1.setLayout(gl_panel_1);
     
    		//--------------LINK
     
    		JPanel Link_P = new JPanel();
    		Link_P.setBounds(20, 22, 295, 100);
    		panel_1.add(Link_P);
    		Link_P.setLayout(null);
    		Link_P.setBorder(BorderFactory.createLineBorder(Color.lightGray));
     
    		JLabel lblLambda = new JLabel("Lambda");
    		lblLambda.setHorizontalAlignment(SwingConstants.RIGHT);
    		lblLambda.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		lblLambda.setBounds(68, 11, 64, 14);
    		Link_P.add(lblLambda);
     
    		JLabel raspolozivost = new JLabel("Raspolozivost");
    		raspolozivost.setHorizontalAlignment(SwingConstants.RIGHT);
    		raspolozivost.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		raspolozivost.setBounds(42, 63, 90, 14);
    		Link_P.add(raspolozivost);
     
    		raspolozivost_txt = new JTextField();
    		raspolozivost_txt.setBounds(142, 61, 127, 20);
    		Link_P.add(raspolozivost_txt);
    		raspolozivost_txt.setColumns(10);
     
    		//java_read_txt callingmet = new java_read_txt();
    		textField = new JTextField();
    		textField.setBounds(142, 9, 127, 20);
    		Link_P.add(textField);
    		textField.setColumns(10);
     
     
    		textField_1 = new JTextField();
    		textField_1.setBounds(142, 34, 127, 20);
    		Link_P.add(textField_1);
    		textField_1.setColumns(10);
     
    		JLabel lblMttr = new JLabel("MTTR");
    		lblMttr.setHorizontalAlignment(SwingConstants.RIGHT);
    		lblMttr.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		lblMttr.setBounds(86, 36, 46, 14);
    		Link_P.add(lblMttr);
     
     
     
     
    		//---------------CVOR
     
    		JPanel Cvor_P = new JPanel();
    		Cvor_P.setBounds(20, 20, 295, 1580);
    		panel_2.add(Cvor_P);
    		Cvor_P.setBorder(BorderFactory.createLineBorder(Color.lightGray));
    		Cvor_P.setLayout(null);
     
    		JLabel Cvor_L = new JLabel("Cvor");
    		Cvor_L.setBounds(2, -5, 29, 24);
    		Cvor_P.add(Cvor_L);
    		Cvor_L.setForeground(new Color(0, 51, 255));
    		Cvor_L.setFont(new Font("SansSerif", Font.PLAIN, 13));
     
    		//--------------MUX/DEMUX
     
     
    		JPanel MUX_DEMUX_P = new JPanel();
    		MUX_DEMUX_P.setBorder(BorderFactory.createLineBorder(Color.lightGray));
    		MUX_DEMUX_P.setBounds(10, 22, 271, 173);
    		Cvor_P.add(MUX_DEMUX_P);
    		MUX_DEMUX_P.setLayout(null);
     
    		textField_2 = new JTextField();
    		textField_2.setColumns(10);
    		textField_2.setBounds(134, 29, 127, 20);
    		MUX_DEMUX_P.add(textField_2);
     
    		textField_3 = new JTextField();
    		textField_3.setColumns(10);
    		textField_3.setBounds(134, 60, 127, 20);
    		MUX_DEMUX_P.add(textField_3);
     
    		textField_4 = new JTextField();
    		textField_4.setColumns(10);
    		textField_4.setBounds(134, 91, 127, 20);
    		MUX_DEMUX_P.add(textField_4);
     
    		JLabel lblLambda_1 = new JLabel("Lambda");
    		lblLambda_1.setHorizontalAlignment(SwingConstants.RIGHT);
    		lblLambda_1.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		lblLambda_1.setBounds(78, 32, 46, 14);
    		MUX_DEMUX_P.add(lblLambda_1);
     
    		JLabel lblMttr_1 = new JLabel("MTTR");
    		lblMttr_1.setHorizontalAlignment(SwingConstants.RIGHT);
    		lblMttr_1.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		lblMttr_1.setBounds(88, 62, 34, 14);
    		MUX_DEMUX_P.add(lblMttr_1);
     
    		JLabel lblBrojKartica = new JLabel("Broj Kartica");
    		lblBrojKartica.setHorizontalAlignment(SwingConstants.RIGHT);
    		lblBrojKartica.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		lblBrojKartica.setBounds(56, 93, 68, 14);
    		MUX_DEMUX_P.add(lblBrojKartica);
     
    		JLabel lblRedundancija = new JLabel("Redundancija");
    		lblRedundancija.setHorizontalAlignment(SwingConstants.RIGHT);
    		lblRedundancija.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		lblRedundancija.setBounds(39, 118, 85, 14);
    		MUX_DEMUX_P.add(lblRedundancija);
     
    		JCheckBox checkBox = new JCheckBox("");
    		checkBox.setBounds(130, 112, 25, 27);
    		MUX_DEMUX_P.add(checkBox);
     
    		JLabel MUX_DEMUX_L = new JLabel("MUX/DEMUX");
    		MUX_DEMUX_L.setBounds(5, 0, 83, 22);
    		MUX_DEMUX_P.add(MUX_DEMUX_L);
    		MUX_DEMUX_L.setForeground(new Color(0, 51, 255));
    		MUX_DEMUX_L.setFont(new Font("SansSerif", Font.PLAIN, 13));
     
    		JLabel lblRaspolozivost = new JLabel("Raspolozivost");
    		lblRaspolozivost.setHorizontalAlignment(SwingConstants.RIGHT);
    		lblRaspolozivost.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		lblRaspolozivost.setBounds(26, 143, 98, 14);
    		MUX_DEMUX_P.add(lblRaspolozivost);
     
    		textField_14 = new JTextField();
    		textField_14.setColumns(10);
    		textField_14.setBounds(134, 141, 127, 20);
    		MUX_DEMUX_P.add(textField_14);
     
     
    		//-----------Tip Cvora
     
    		JPanel Tip_Cvora_P = new JPanel();
    		Tip_Cvora_P.setLayout(null);
    		Tip_Cvora_P.setBorder(BorderFactory.createLineBorder(Color.lightGray));
    		Tip_Cvora_P.setBounds(10, 1398, 271, 173);
    		Cvor_P.add(Tip_Cvora_P);
     
    		textField_34 = new JTextField();
    		textField_34.setColumns(10);
    		textField_34.setBounds(134, 49, 127, 20);
    		Tip_Cvora_P.add(textField_34);
     
    		JLabel lblZavrsniCvor = new JLabel("Zavrsni Cvor");
    		lblZavrsniCvor.setHorizontalAlignment(SwingConstants.RIGHT);
    		lblZavrsniCvor.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		lblZavrsniCvor.setBounds(78, 24, 98, 14);
    		Tip_Cvora_P.add(lblZavrsniCvor);
     
    		JLabel label_37 = new JLabel("Tip Cvora");
    		label_37.setForeground(new Color(0, 51, 255));
    		label_37.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_37.setBounds(5, 0, 83, 22);
    		Tip_Cvora_P.add(label_37);
     
    		JLabel label_38 = new JLabel("Raspolozivost");
    		label_38.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_38.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_38.setBounds(26, 129, 98, 14);
    		Tip_Cvora_P.add(label_38);
     
    		textField_37 = new JTextField();
    		textField_37.setColumns(10);
    		textField_37.setBounds(134, 127, 127, 20);
    		Tip_Cvora_P.add(textField_37);
     
    		JLabel label39 = new JLabel("Raspolozivost");
    		label39.setHorizontalAlignment(SwingConstants.RIGHT);
    		label39.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label39.setBounds(26, 49, 98, 14);
    		Tip_Cvora_P.add(label39);
     
    		JLabel lblProlazniCvor = new JLabel("Prolazni Cvor");
    		lblProlazniCvor.setHorizontalAlignment(SwingConstants.RIGHT);
    		lblProlazniCvor.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		lblProlazniCvor.setBounds(78, 104, 98, 14);
    		Tip_Cvora_P.add(lblProlazniCvor);
     
    		JLabel label_40 = new JLabel("-------------------------------------------------------------------");
    		label_40.setBounds(5, 80, 271, 14);
    		Tip_Cvora_P.add(label_40);
     
     
    		//---------------POA_Linijsko_pojacalo
     
    		JPanel POA_Linijsko_pojacalo_P = new JPanel();
    		POA_Linijsko_pojacalo_P.setLayout(null);
    		POA_Linijsko_pojacalo_P.setBorder(BorderFactory.createLineBorder(Color.lightGray));
    		POA_Linijsko_pojacalo_P.setBounds(10, 1230, 271, 157);
    		Cvor_P.add(POA_Linijsko_pojacalo_P);
     
    		textField_30 = new JTextField();
    		textField_30.setColumns(10);
    		textField_30.setBounds(134, 29, 127, 20);
    		POA_Linijsko_pojacalo_P.add(textField_30);
     
    		textField_31 = new JTextField();
    		textField_31.setColumns(10);
    		textField_31.setBounds(134, 60, 127, 20);
    		POA_Linijsko_pojacalo_P.add(textField_31);
     
    		textField_32 = new JTextField();
    		textField_32.setColumns(10);
    		textField_32.setBounds(134, 91, 127, 20);
    		POA_Linijsko_pojacalo_P.add(textField_32);
     
    		JLabel label_28 = new JLabel("Lambda");
    		label_28.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_28.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_28.setBounds(78, 32, 46, 14);
    		POA_Linijsko_pojacalo_P.add(label_28);
     
    		JLabel label_29 = new JLabel("MTTR");
    		label_29.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_29.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_29.setBounds(88, 62, 34, 14);
    		POA_Linijsko_pojacalo_P.add(label_29);
     
    		JLabel label_30 = new JLabel("Broj Kartica");
    		label_30.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_30.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_30.setBounds(56, 93, 68, 14);
    		POA_Linijsko_pojacalo_P.add(label_30);
     
    		JLabel label_31 = new JLabel("POA Linijsko pojacalo");
    		label_31.setForeground(new Color(0, 51, 255));
    		label_31.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_31.setBounds(5, 0, 135, 22);
    		POA_Linijsko_pojacalo_P.add(label_31);
     
    		JLabel label_32 = new JLabel("Raspolozivost");
    		label_32.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_32.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_32.setBounds(29, 124, 98, 14);
    		POA_Linijsko_pojacalo_P.add(label_32);
     
    		textField_33 = new JTextField();
    		textField_33.setColumns(10);
    		textField_33.setBounds(134, 122, 127, 20);
    		POA_Linijsko_pojacalo_P.add(textField_33);
     
     
    		//----------------LOA_Linijsko_Snage
     
    		JPanel LOA_Linijsko_Snage_P = new JPanel();
    		LOA_Linijsko_Snage_P.setLayout(null);
    		LOA_Linijsko_Snage_P.setBorder(BorderFactory.createLineBorder(Color.lightGray));
    		LOA_Linijsko_Snage_P.setBounds(10, 1062, 271, 157);
    		Cvor_P.add(LOA_Linijsko_Snage_P);
     
    		textField_26 = new JTextField();
    		textField_26.setColumns(10);
    		textField_26.setBounds(134, 29, 127, 20);
    		LOA_Linijsko_Snage_P.add(textField_26);
     
    		textField_27 = new JTextField();
    		textField_27.setColumns(10);
    		textField_27.setBounds(134, 60, 127, 20);
    		LOA_Linijsko_Snage_P.add(textField_27);
     
    		textField_28 = new JTextField();
    		textField_28.setColumns(10);
    		textField_28.setBounds(134, 91, 127, 20);
    		LOA_Linijsko_Snage_P.add(textField_28);
     
    		JLabel label_23 = new JLabel("Lambda");
    		label_23.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_23.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_23.setBounds(78, 32, 46, 14);
    		LOA_Linijsko_Snage_P.add(label_23);
     
    		JLabel label_24 = new JLabel("MTTR");
    		label_24.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_24.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_24.setBounds(88, 62, 34, 14);
    		LOA_Linijsko_Snage_P.add(label_24);
     
    		JLabel label_25 = new JLabel("Broj Kartica");
    		label_25.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_25.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_25.setBounds(56, 93, 68, 14);
    		LOA_Linijsko_Snage_P.add(label_25);
     
    		JLabel label_26 = new JLabel("LOA Linijsko_Snage");
    		label_26.setForeground(new Color(0, 51, 255));
    		label_26.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_26.setBounds(5, 0, 135, 22);
    		LOA_Linijsko_Snage_P.add(label_26);
     
    		JLabel label_27 = new JLabel("Raspolozivost");
    		label_27.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_27.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_27.setBounds(29, 124, 98, 14);
    		LOA_Linijsko_Snage_P.add(label_27);
     
    		textField_29 = new JTextField();
    		textField_29.setColumns(10);
    		textField_29.setBounds(134, 122, 127, 20);
    		LOA_Linijsko_Snage_P.add(textField_29);
     
     
    		//---------------BOA_Pojacalo_Snage
     
    		JPanel BOA_Pojacalo_Snage_P = new JPanel();
    		BOA_Pojacalo_Snage_P.setLayout(null);
    		BOA_Pojacalo_Snage_P.setBorder(BorderFactory.createLineBorder(Color.lightGray));
    		BOA_Pojacalo_Snage_P.setBounds(10, 894, 271, 157);
    		Cvor_P.add(BOA_Pojacalo_Snage_P);
     
    		textField_22 = new JTextField();
    		textField_22.setColumns(10);
    		textField_22.setBounds(134, 29, 127, 20);
    		BOA_Pojacalo_Snage_P.add(textField_22);
     
    		textField_23 = new JTextField();
    		textField_23.setColumns(10);
    		textField_23.setBounds(134, 60, 127, 20);
    		BOA_Pojacalo_Snage_P.add(textField_23);
     
    		textField_24 = new JTextField();
    		textField_24.setColumns(10);
    		textField_24.setBounds(134, 91, 127, 20);
    		BOA_Pojacalo_Snage_P.add(textField_24);
     
    		JLabel label_18 = new JLabel("Lambda");
    		label_18.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_18.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_18.setBounds(78, 32, 46, 14);
    		BOA_Pojacalo_Snage_P.add(label_18);
     
    		JLabel label_19 = new JLabel("MTTR");
    		label_19.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_19.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_19.setBounds(88, 62, 34, 14);
    		BOA_Pojacalo_Snage_P.add(label_19);
     
    		JLabel label_20 = new JLabel("Broj Kartica");
    		label_20.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_20.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_20.setBounds(56, 93, 68, 14);
    		BOA_Pojacalo_Snage_P.add(label_20);
     
    		JLabel label_21 = new JLabel("BOA Pojacalo Snage");
    		label_21.setForeground(new Color(0, 51, 255));
    		label_21.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_21.setBounds(5, 0, 135, 22);
    		BOA_Pojacalo_Snage_P.add(label_21);
     
    		JLabel label_22 = new JLabel("Raspolozivost");
    		label_22.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_22.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_22.setBounds(29, 124, 98, 14);
    		BOA_Pojacalo_Snage_P.add(label_22);
     
    		textField_25 = new JTextField();
    		textField_25.setColumns(10);
    		textField_25.setBounds(134, 122, 127, 20);
    		BOA_Pojacalo_Snage_P.add(textField_25);
     
     
    		//---------------Opticki_Prespojnik_P
     
    		JPanel Opticki_Prespojnik_P = new JPanel();
    		Opticki_Prespojnik_P.setBorder(BorderFactory.createLineBorder(Color.lightGray));
    		Opticki_Prespojnik_P.setLayout(null);
    		Opticki_Prespojnik_P.setBounds(10, 206, 271, 173);
    		Cvor_P.add(Opticki_Prespojnik_P);
     
    		textField_5 = new JTextField();
    		textField_5.setColumns(10);
    		textField_5.setBounds(134, 29, 127, 20);
    		Opticki_Prespojnik_P.add(textField_5);
     
    		textField_6 = new JTextField();
    		textField_6.setColumns(10);
    		textField_6.setBounds(134, 60, 127, 20);
    		Opticki_Prespojnik_P.add(textField_6);
     
    		textField_7 = new JTextField();
    		textField_7.setColumns(10);
    		textField_7.setBounds(134, 91, 127, 20);
    		Opticki_Prespojnik_P.add(textField_7);
     
    		JLabel label_3 = new JLabel("Lambda");
    		label_3.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_3.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_3.setBounds(78, 32, 46, 14);
    		Opticki_Prespojnik_P.add(label_3);
     
    		JLabel label_4 = new JLabel("MTTR");
    		label_4.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_4.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_4.setBounds(88, 62, 34, 14);
    		Opticki_Prespojnik_P.add(label_4);
     
    		JLabel label_5 = new JLabel("Broj Kartica");
    		label_5.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_5.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_5.setBounds(56, 93, 68, 14);
    		Opticki_Prespojnik_P.add(label_5);
     
    		JLabel label_6 = new JLabel("Redundancija");
    		label_6.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_6.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_6.setBounds(39, 118, 85, 14);
    		Opticki_Prespojnik_P.add(label_6);
     
    		JCheckBox checkBox_1 = new JCheckBox("");
    		checkBox_1.setBounds(130, 112, 25, 27);
    		Opticki_Prespojnik_P.add(checkBox_1);
     
    		JLabel lblOptickiPrespojnik = new JLabel("Opticki Prespojnik");
    		lblOptickiPrespojnik.setForeground(new Color(0, 51, 255));
    		lblOptickiPrespojnik.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		lblOptickiPrespojnik.setBounds(5, 0, 135, 22);
    		Opticki_Prespojnik_P.add(lblOptickiPrespojnik);
     
    		JLabel label_9 = new JLabel("Raspolozivost");
    		label_9.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_9.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_9.setBounds(26, 143, 98, 14);
    		Opticki_Prespojnik_P.add(label_9);
     
    		textField_15 = new JTextField();
    		textField_15.setColumns(10);
    		textField_15.setBounds(134, 141, 127, 20);
    		Opticki_Prespojnik_P.add(textField_15);
     
     
    		//-------------------Fiksni_Predajnik
     
    		JPanel Fiksni_Predajnik_P = new JPanel();
    		Fiksni_Predajnik_P.setLayout(null);
    		Fiksni_Predajnik_P.setBorder(BorderFactory.createLineBorder(Color.lightGray));
    		Fiksni_Predajnik_P.setBounds(10, 390, 271, 157);
    		Cvor_P.add(Fiksni_Predajnik_P);
     
    		textField_8 = new JTextField();
    		textField_8.setColumns(10);
    		textField_8.setBounds(134, 29, 127, 20);
    		Fiksni_Predajnik_P.add(textField_8);
     
    		textField_9 = new JTextField();
    		textField_9.setColumns(10);
    		textField_9.setBounds(134, 60, 127, 20);
    		Fiksni_Predajnik_P.add(textField_9);
     
    		textField_10 = new JTextField();
    		textField_10.setColumns(10);
    		textField_10.setBounds(134, 91, 127, 20);
    		Fiksni_Predajnik_P.add(textField_10);
     
    		JLabel label = new JLabel("Lambda");
    		label.setHorizontalAlignment(SwingConstants.RIGHT);
    		label.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label.setBounds(78, 32, 46, 14);
    		Fiksni_Predajnik_P.add(label);
     
    		JLabel label_1 = new JLabel("MTTR");
    		label_1.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_1.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_1.setBounds(88, 62, 34, 14);
    		Fiksni_Predajnik_P.add(label_1);
     
    		JLabel label_2 = new JLabel("Broj Kartica");
    		label_2.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_2.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_2.setBounds(56, 93, 68, 14);
    		Fiksni_Predajnik_P.add(label_2);
     
    		JLabel lblFiksniPredajnik = new JLabel("Fiksni Predajnik");
    		lblFiksniPredajnik.setForeground(new Color(0, 51, 255));
    		lblFiksniPredajnik.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		lblFiksniPredajnik.setBounds(5, 0, 135, 22);
    		Fiksni_Predajnik_P.add(lblFiksniPredajnik);
     
    		JLabel label_13 = new JLabel("Raspolozivost");
    		label_13.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_13.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_13.setBounds(29, 124, 98, 14);
    		Fiksni_Predajnik_P.add(label_13);
     
    		textField_16 = new JTextField();
    		textField_16.setColumns(10);
    		textField_16.setBounds(134, 122, 127, 20);
    		Fiksni_Predajnik_P.add(textField_16);
     
     
    		//-----------EDFA
     
    		JPanel EDFA_P = new JPanel();
    		EDFA_P.setBounds(10, 726, 271, 157);
    		EDFA_P.setBorder(BorderFactory.createLineBorder(Color.lightGray));
    		Cvor_P.add(EDFA_P);
    		EDFA_P.setLayout(null);
     
    		textField_18 = new JTextField();
    		textField_18.setColumns(10);
    		textField_18.setBounds(134, 29, 127, 20);
    		EDFA_P.add(textField_18);
     
    		textField_19 = new JTextField();
    		textField_19.setColumns(10);
    		textField_19.setBounds(134, 60, 127, 20);
    		EDFA_P.add(textField_19);
     
    		textField_20 = new JTextField();
    		textField_20.setColumns(10);
    		textField_20.setBounds(134, 91, 127, 20);
    		EDFA_P.add(textField_20);
     
    		JLabel label_11 = new JLabel("Lambda");
    		label_11.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_11.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_11.setBounds(78, 32, 46, 14);
    		EDFA_P.add(label_11);
     
    		JLabel label_14 = new JLabel("MTTR");
    		label_14.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_14.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_14.setBounds(88, 62, 34, 14);
    		EDFA_P.add(label_14);
     
    		JLabel label_15 = new JLabel("Broj Kartica");
    		label_15.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_15.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_15.setBounds(56, 93, 68, 14);
    		EDFA_P.add(label_15);
     
    		JLabel label_16 = new JLabel("EDFA");
    		label_16.setForeground(new Color(0, 51, 255));
    		label_16.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_16.setBounds(5, 0, 135, 22);
    		EDFA_P.add(label_16);
     
    		JLabel label_17 = new JLabel("Raspolozivost");
    		label_17.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_17.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_17.setBounds(29, 124, 98, 14);
    		EDFA_P.add(label_17);
     
    		textField_21 = new JTextField();
    		textField_21.setColumns(10);
    		textField_21.setBounds(134, 122, 127, 20);
    		EDFA_P.add(textField_21);
     
     
    		//----------------Fiksni_Prijemnik
     
    		JPanel Fiksni_Prijemnik_P = new JPanel();
    		Fiksni_Prijemnik_P.setLayout(null);
    		Fiksni_Prijemnik_P.setBorder(BorderFactory.createLineBorder(Color.lightGray));
    		Fiksni_Prijemnik_P.setBounds(10, 558, 271, 157);
    		Cvor_P.add(Fiksni_Prijemnik_P);
     
    		textField_11 = new JTextField();
    		textField_11.setColumns(10);
    		textField_11.setBounds(134, 29, 127, 20);
    		Fiksni_Prijemnik_P.add(textField_11);
     
    		textField_12 = new JTextField();
    		textField_12.setColumns(10);
    		textField_12.setBounds(134, 60, 127, 20);
    		Fiksni_Prijemnik_P.add(textField_12);
     
    		textField_13 = new JTextField();
    		textField_13.setColumns(10);
    		textField_13.setBounds(134, 91, 127, 20);
    		Fiksni_Prijemnik_P.add(textField_13);
     
    		JLabel label_7 = new JLabel("Lambda");
    		label_7.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_7.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_7.setBounds(78, 32, 46, 14);
    		Fiksni_Prijemnik_P.add(label_7);
     
    		JLabel label_8 = new JLabel("MTTR");
    		label_8.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_8.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_8.setBounds(88, 62, 34, 14);
    		Fiksni_Prijemnik_P.add(label_8);
     
    		JLabel label_10 = new JLabel("Broj Kartica");
    		label_10.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_10.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_10.setBounds(56, 93, 68, 14);
    		Fiksni_Prijemnik_P.add(label_10);
     
    		JLabel lblFiksniPrijemnik = new JLabel("Fiksni Prijemnik");
    		lblFiksniPrijemnik.setForeground(new Color(0, 51, 255));
    		lblFiksniPrijemnik.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		lblFiksniPrijemnik.setBounds(5, 0, 135, 22);
    		Fiksni_Prijemnik_P.add(lblFiksniPrijemnik);
     
    		JLabel label_12 = new JLabel("Raspolozivost");
    		label_12.setHorizontalAlignment(SwingConstants.RIGHT);
    		label_12.setFont(new Font("SansSerif", Font.PLAIN, 13));
    		label_12.setBounds(29, 124, 98, 14);
    		Fiksni_Prijemnik_P.add(label_12);
     
    		textField_17 = new JTextField();
    		textField_17.setColumns(10);
    		textField_17.setBounds(134, 122, 127, 20);
    		Fiksni_Prijemnik_P.add(textField_17);
     
    		JButton Odbaci_B = new JButton("Odbaci");
    		Odbaci_B.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
            		f_elementi.this.dispose();
    			}
    		});
    		Odbaci_B.setBounds(230, 389, 109, 23);
    		panel.add(Odbaci_B);
     
    		JButton Prihvati_B = new JButton("Prihvati");
    		Prihvati_B.setBounds(105, 389, 109, 23);
    		panel.add(Prihvati_B);
     
     
    		//----------------------------
     
    	}
     
    }

    and this is my class where is reader
    import java.io.FileReader;
    import java.io.IOException;
     
     
    import org.json.simple.JSONObject;
    import org.json.simple.parser.JSONParser;
    import org.json.simple.parser.ParseException;
     
    public class java_read_txt {
     
    	public static void main(String[] args) throws ParseException {
     
    	JSONParser parser = new JSONParser();
     
    	try {
     
    		Object obj = parser.parse(new FileReader("c:\\mreza3.json"));
     
    		JSONObject jsonObject = (JSONObject) obj;
     
    		long age = (Long) jsonObject.get("LinkMTTR");
    		System.out.println(age);
     
     
    	} catch (IOException e) {
    		e.printStackTrace();
     
    	}
     
      }
     
    }

    and i need to connect my method to a first textfield
    Last edited by nautilusz; January 21st, 2012 at 09:56 PM.

  27. #23
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: reading and witing to txt file


  28. The Following User Says Thank You to Norm For This Useful Post:

    nautilusz (January 22nd, 2012)

  29. #24
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: reading and witing to txt file

    thx so much .. i finally got it, one of the problems was that my reader was written under void main,
    so i created separate method called reader, made it string and taking one argument so i can use if loop for other textfields and return string value.
    so my reader class looks like this now
    public class java_read_txt {
     
     
        public static void main(String[] args) {
     
        }
     
     
        public static String reader(String b){
        JSONParser parser = new JSONParser();
     
    	try {
     
    		Object obj = parser.parse(new FileReader("mreza3.json"));
     
    		JSONObject jsonObject = (JSONObject) obj;
    		if (b == "lambda")
    		{
    		long LinkLambda = (long) jsonObject.get("LinkLambda");
    		String LinkLambda1 = Long.toString(LinkLambda);
    		//System.out.println(LinkLambda);		
    		return LinkLambda1;
    		}
    		else if (b == "MTTR")
    		{
    			long LinkMTTR = (Long) jsonObject.get("LinkMTTR");
    			String LinkMTTR1 = Long.toString(LinkMTTR);
    			//System.out.println(LinkMTTR);	
    			return LinkMTTR1;
     
    		}
     
     
    	} catch (Exception e) {}
    	return null;
      }
     
     
    }

    and in my class where are textfields, code look like this

    String lambda = java_read_txt.reader("lambda");
    		textField = new JTextField();
    		textField.setHorizontalAlignment(SwingConstants.RIGHT);
    		textField.setBounds(142, 9, 127, 20);
    		Link_P.add(textField);
    		textField.setColumns(10);
    		textField.setText(lambda);

  30. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: reading and witing to txt file

    if (b == "lambda")
    You should use the equals() method for comparing Strings, not the == operator.

  31. The Following User Says Thank You to Norm For This Useful Post:

    nautilusz (January 22nd, 2012)

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: December 2nd, 2011, 11:53 AM
  2. Reading from a file
    By NeedzABetterSN in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 5th, 2011, 08:07 AM
  3. Reading a file
    By Soccer13 in forum Java Theory & Questions
    Replies: 2
    Last Post: October 26th, 2010, 08:55 PM
  4. Reading file
    By nasi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 3rd, 2010, 03:14 AM
  5. Anyone Help me in XML file Reading??????????
    By goplrao in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 2nd, 2010, 11:04 AM