Results 1 to 6 of 6

Thread: Basic java

  1. #1
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    11

    Smile Basic java

    Hello, im new to java. Could any one help me with a simple text problem? I want to make a program that first shows a textfeild that you can write text in. Sends the text to a mysql database, then sends it back and displays it in the same box as the textfield. I would like to do this on a very basic level =) any tips or ideas? thanks =)

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    14

    Default

    What have you done so far and where exactly are you stuck?

  3. #3
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    11

    Default

    I am at the startpoint. And my textfield dont work at all =(

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    14

    Default

    Describe "dont work at all".

  5. #5
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    11

    Default

    This is the text box i had in mind
    import java.awt.TextField;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.FocusEvent;
    import org.eclipse.swt.events.FocusListener;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Text;

    public class chat {

    Display d;

    Shell s;

    void TextField() {
    d = new Display();
    s = new Shell(d);
    s.setSize(250, 250);
    s.setText("Chat box");
    Text text1 = new Text(s, SWT.WRAP | SWT.BORDER);
    text1.setBounds(100, 50, 100, 20);
    text1.setTextLimit(100);
    text1.setText("12345");
    Text text2 = new Text(s, SWT.SINGLE | SWT.BORDER);
    text2.setBounds(100, 75, 100, 20);
    text2.setTextLimit(30);


    FocusListener focusListener = new FocusListener() {
    public void focusGained(FocusEvent e) {
    Text t = (Text) e.widget;
    t.selectAll();
    }

    public void focusLost(FocusEvent e) {
    Text t = (Text) e.widget;
    if (t.getSelectionCount() > 0) {
    t.clearSelection();
    }
    }
    };
    text1.addFocusListener(focusListener);
    text2.addFocusListener(focusListener);
    s.open();
    while (!s.isDisposed()) {
    if (!d.readAndDispatch())
    d.sleep();
    }
    d.dispose();
    }

    public static void main(String[] arg) {
    new TextField();


    }
    }
    And I do have the "java.awt.TextField;" library. When i run this in eclipse i get no errors but nothing hapens at all =S there should be a box? Am i wrong? :)

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    14

Similar Threads

  1. Basic Java help, AIM?
    By jkswebsite in forum New To Java
    Replies: 4
    Last Post: 07-11-2012, 06:17 PM
  2. basic Java looping
    By ace_hl in forum New To Java
    Replies: 16
    Last Post: 09-03-2009, 01:49 AM
  3. basic java
    By vijay24805 in forum New To Java
    Replies: 25
    Last Post: 04-14-2009, 02:46 AM
  4. basic java help
    By adred in forum New To Java
    Replies: 0
    Last Post: 03-08-2008, 12:36 PM
  5. Help with basic shapes in java
    By carl in forum Java 2D
    Replies: 1
    Last Post: 07-31-2007, 11:40 PM

Posting Permissions

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