Results 1 to 3 of 3
  1. #1
    nautilusz is offline Member
    Join Date
    Jan 2012
    Posts
    1
    Rep Power
    0

    Post connecting json read method to textfield in class

    i have created my gui, with textfields, and json reader,and i need to connect variable from my reader method to the textfield which is in my main class.
    any suggestions how to do that? currently trying to connect just one element to first textfield in this case, reader gives me number "10" in conosole, which means it's working fine, variable with that number has to be written it textfield

    my gui code
    Java Code:
    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);
    		
    		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);
    		
    		
    		//----------------------------
    	
    	}
    	
    }
    this is my Json reader code
    Java Code:
    import java.io.FileReader;
    import org.json.simple.JSONObject;
    import org.json.simple.parser.JSONParser;
     
    public class java_read_txt {
    	
    	
        public static void main(String[] args) {
     
    	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 (Exception e) {}
      }
     
    }
    json file has:
    e.g. these elements


    "LinkLambda" : 100,
    "LinkMTTR" : 10,
    "LinkRaspolozivost" : 0

    "MuxDemuxLambda" : 100,
    "MuxDemuxMTTR" : 10,
    "MuxDemuxBrojKartica" : 10,
    "MuxDemuxRaspolozivost" : 0

    Sorry for long code post, but i hope so it will be clearer to see what I need to do.
    Last edited by nautilusz; 01-22-2012 at 07:55 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: connecting json read method to textfield in class

    i need to connect variable from my reader method to the textfield which is in my main class.
    A way to do it. Have the reader method return the String that you want to put in the textfield:
    Call the method, it gets the String and returns it, then have the calling code put that String into the textfield.
    String theVal = theMethodToReadString();
    textField.setTetx(theVal);

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

Similar Threads

  1. Read in Int from return method in other class?
    By WoodyHD in forum New To Java
    Replies: 6
    Last Post: 01-18-2012, 06:02 AM
  2. Replies: 1
    Last Post: 10-17-2011, 01:00 AM
  3. JDBC not connecting from Thread Class
    By shorawitz in forum Threads and Synchronization
    Replies: 1
    Last Post: 11-15-2010, 11:38 PM
  4. Replies: 8
    Last Post: 11-12-2010, 03:00 PM
  5. JSON Lib: json-lib-1.0-jdk13.jar
    By Raghuraman K in forum Advanced Java
    Replies: 3
    Last Post: 05-13-2010, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •