Results 1 to 4 of 4

Thread: newby question

  1. #1
    virgil27 is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default newby question

    Hello

    I'm Virgil and I'm completly new to Java. Now I'm busy for my study.
    I'm trying to create a GUI which makes it able for a user to give inpunt in a textfield.
    These entrys are used to make a new variable. This variable is a command.
    I don't know how I can use 2 strings 2 make 1 new variable wich is a command.

    Example:

    var1 = TABLE CLLI;ADD "string1" 4034 30 "string2"

    This var1 has 2 be written to a output file.
    How can I do this?
    Can someone help me out?

    Regards,

    Virgil

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;


    public class StringTemplate extends JFrame
    implements ActionListener {

    private JTextField string1Field, string2Field;
    private JTextField resultField;
    private JLabel string1Label, string2Label;
    private JLabel resultLabel;
    private JButton saveButton;


    public static void main(String[] args) {
    StringTemplate frame = new StringTemplate();
    frame.setSize(250, 500);
    frame.createGUI();
    frame.show();
    }

    private void createGUI() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    Container window = getContentPane();
    window.setLayout(new FlowLayout());

    string1Label = new JLabel("Cramer ID: ");
    window.add(string1Label);

    string1Field = new JTextField(20);
    window.add(string1Field);

    string2Label = new JLabel("NAW gegevens: ");
    window.add(string2Label);

    string2Field = new JTextField(20);
    window.add(string2Field);


    resultLabel = new JLabel("result is: ");
    window.add(resultLabel);

    resultField = new JTextField(20);
    window.add(resultField);

    saveButton = new JButton("Save");
    window.add(saveButton);
    saveButton.addActionListener(this);
    }

    public void actionPerformed(ActionEvent event) {
    String result ="";
    if (event.getSource() == saveButton) {
    String string1 = string1Field.getText();
    String string2 = string2Field.getText();
    String Clli = "TABLE CLLI;ADD +string1 4034 30 +string2";
    resultField.setText(Clli);
    }
    }
    }

  2. #2
    virgil27 is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default

    I know now how to do it with the varaibles.
    But know I only need to know how I can print this to a file.
    Can someone help me with that?
    Each string has to be on a new line


    String string2 = string2Field.getText();
    String string3 = string3Field.getText();
    String string4 = string4Field.getText();
    String string5 = string5Field.getText();
    String clli = "TABLE CLLI;ADD " + string2+ " 4034 30 " + string3;
    String trkgrp = "TABLE TRKGRP;ADD " + string2 + " PRA 0 PRAC NCRT ASEQ N $ $" ;
    String trksgrp = "TABLE TRKSGRP;ADD " + string2 + " 0 DS1SIG ISDN 20 20 87Q931 2 Y STAND+ NETWORK PT_PT USER N UNEQ 255 N PRIMAP GWC " + string4 + " " + string5 + " 64K HDLC $ $";
    String trkmem = "TABLE TRKMEM;ver off";


    Regards,

  3. #3
    bnson is offline Artemis
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    Hi, The example simple can help you.

    Java Code:
    	public void writeFile()
    	{
      		try
    		{
    	        // Create file 
            	FileWriter fstream = new FileWriter("D:\\out.txt");
            	BufferedWriter out = new BufferedWriter(fstream);
    
                    // Writing data to file out.txt
            	out.write("Hello Java \\n");
            	out.newLine();   // Created a new line.
            	out.flush(); // Flushes this output stream and forces any buffered output bytes to be written out. 
            	out.write("Good Morning!");
            	out.newLine(); 
            	out.flush();  
            	out.write("Ohio!");        	
    
           		//Close the output stream
           		out.close();
      		}
      		catch (Exception e)
      		{
           		//Catch exception if any
          		System.err.println("Error: " + e.getMessage());
      		}
      	}
    If you want to learn about the files in java, you should see "File I / O Basic"

  4. #4
    virgil27 is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default

    Thank you.
    That's a big help.
    I used this and my GUI is now ready for fase 1.

    Is there also such a thing possible to make a telnet connection to a server with Java, and read the generated file with commands?

    I normally would do this with Perl, but I cannot use this voor my study at the moment :(


    Regards,

Similar Threads

  1. Question concerning question marks and colons
    By jim01 in forum New To Java
    Replies: 17
    Last Post: 01-14-2011, 12:05 AM
  2. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  3. Newby
    By Zoidy in forum New To Java
    Replies: 5
    Last Post: 11-06-2010, 12:11 PM
  4. Newby need help with pop up banner
    By Lapsesuu in forum New To Java
    Replies: 0
    Last Post: 12-04-2008, 11:01 AM
  5. Java newby
    By violinssoundcool in forum New To Java
    Replies: 6
    Last Post: 01-26-2008, 05:28 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
  •