JTextField(Document, string, int)

Dear friends,
Could you just tell me how can I fix the size of the JTextField,
such as just accept the maximum number of digits or characters in JTextField...
I cant create the Document....
Could anyone give me a tips?

I found the best way to do this is to subclass PlainDocument as follows:
public class MyTextDoc extends PlainDocument
    int maxCharacters;
    public MyTextDoc(int maxChars) {
        maxCharacters = maxChars;
    public void insertString( int offs, String str,  AttributeSet a )
                throws BadLocationException {
        if( (getLength() + str.length()) <= maxCharacters)
            super.insertString(offs, str, a);
        else
            Toolkit.getDefaultToolkit().beep();
}I then use this document in the constructor for all my JTextFields.
I'm not sure what you mean by "I cant create the Document...."
Cheers
Gary

Similar Messages

  • Checking if input into JTextField is an int value

    Is there any way that you can check whether the String entered into a JTextField represents an int?
    Thanks for the help!
    Wallace

      JTextField field = ...
      try
        int value = Integer.valueOf(field.getText).intValue();
      catch(NumberFormatException)
        // not a number
      }

  • HELP ON java.lang.String,int

    Im very new to java.please help!!!
    im having this error after compiling this:-
    public boolean setBookname(String newName)
              if (newName >0)
                   BookName = newName;
              else
                   return false;
    A:\Book.java:30: operator > cannot be applied to java.lang.String,int
              if (newName >0)
    ^
    1 error
    Process completed.
    thank u!

    The OP should read about IllegalArgumentException.Indeed. And a few other things as well...
    http://java.sun.com/docs/books/tutorial/
    http://java.sun.com/learning/new2java/index.html
    http://javaalmanac.com
    http://www.jguru.com
    http://www.javaranch.com
    Bruce Eckel's Thinking in Java
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java

  • JTextField and String

    Hi,
    I have this few lines :
    JLabel LNSociete = new JLabel( "Nom ");
    LNSociete.setBounds(160,5,100,20);
    c.add(LNSociete);
    INSociete = new JTextField();
    INSociete.setBounds(210,5,150,20);
    c.add(INSociete);
    LNSociete.setLabelFor( INSociete);
    NICC = INSociete.getText();
    my NICC is define as : String NICC = new String();
    and INSociete as a JTextField
    When I'm looking in my frame I have a name in the INSociete fields.
    I WANT receive the text in my NICC I saw or I modified in my frame, but I have " " in my NICC string.
    regards
    Thierry

    As Kamran said, you will need a listener to get the text.
    You have written the code to set up the component but accessing the text must be event driven. As written, your code to get the text happens immediately after the textfield is setup so the user doesn't have time to enter the text before you try to get it out.
    When the user enters the text (and hits return, unless you are using a focuslost listener that hears when the component loses focus or a document listener that hears every keystroke) then an event is triggered that you can write a listener to handle. The listener code then can get the text into NICC.
    I suggest you have a look at the swing tutorial for text components, especially: http://java.sun.com/docs/books/tutorial/uiswing/components/simpletext.html#textfield
    has an example action listener (user has to hit return to triger an action event on a textfield).
    Hope that helps,
    Scott

  • From JTextField into string array

    hello,
    Me and my friend are currently doing a cryptography project for UNI. We are required to read in a word from the JTextField into an array. the problem is the whole word seems to be going into the array as one element. Is there any way to read in each letter in the word into a seperate element of the array??

    Well you can always read the value in the textfield, convert it to a character array and then as you transfer each character to your string array you add a blank string to it, so then it becomes a string.
    Example:
    String sentence = "hello, I am a really loooooooooong string";
    String[] stringArray = new String[sentence.length()];
    char[] charArray = sentence.toCharArray();
    for (int count = 0; count < sentence.length(); count++)
         stringArray[count] = charArray[count] + "";I hope this helps.

  • JTextField to String?

    Hi
    Can anyone tell me how i can extract the text i entered in a JTextField to a String?
    I have two programs that are connected, one the driver of the other
    I tried String string = jTextField.getString();
    all seem fine when i print it, but when i try to access the string from the other program it gives the string a null value, can anyone help me?
    Regard
    Eben

    Program one:
    * RaceScreen.java
    * Created on September 7, 2008, 11:18 AM
    package cargame;
    import java.awt.event.ActionListener;
    * @author  DieBlouBaba
    public class RaceScreen extends javax.swing.JFrame implements ActionListener {
    String pa2,un2;
        /** Creates new form RaceScreen */
        public RaceScreen() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
        private void initComponents() {
            Login = new javax.swing.JButton();
            Newuser = new javax.swing.JButton();
            UserScreenHelp = new javax.swing.JButton();
            UserScreenExit = new javax.swing.JButton();
            Heading = new javax.swing.JLabel();
            setTitle("Start Page");
            setBackground(new java.awt.Color(1, 1, 1));
            setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
            Login.setText("Log In");
            Login.addActionListener(this);
            Newuser.setText("Create New User");
            Newuser.addActionListener(this);
            UserScreenHelp.setText("Help");
            UserScreenExit.setText("Exit");
            UserScreenExit.addActionListener(this);
            Heading.setFont(new java.awt.Font("Bauhaus 93", 1, 24)); // NOI18N
            Heading.setText("Race Game");
            Heading.setDebugGraphicsOptions(javax.swing.DebugGraphics.BUFFERED_OPTION);
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .add(UserScreenHelp)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 269, Short.MAX_VALUE)
                    .add(UserScreenExit))
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .add(135, 135, 135)
                    .add(Heading, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(108, 108, 108))
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(76, Short.MAX_VALUE)
                    .add(Login, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 111, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                    .add(Newuser)
                    .add(61, 61, 61))
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .add(Heading, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 34, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 50, Short.MAX_VALUE)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(Newuser)
                        .add(Login))
                    .add(84, 84, 84))
                .add(layout.createSequentialGroup()
                    .add(168, 168, 168)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(UserScreenExit)
                        .add(UserScreenHelp)))
            pack();
        // Code for dispatching events from components to event handlers.
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == Login) {
                RaceScreen.this.LoginActionPerformed(evt);
            else if (evt.getSource() == Newuser) {
                RaceScreen.this.NewuserActionPerformed(evt);
            else if (evt.getSource() == UserScreenExit) {
                RaceScreen.this.UserScreenExitActionPerformed(evt);
        }// </editor-fold>                       
    private void UserScreenExitActionPerformed(java.awt.event.ActionEvent evt) {                                              
    System.exit(0);
    private void LoginActionPerformed(java.awt.event.ActionEvent evt) {                                     
    new Login().setVisible(true);
    Login login = new Login();
    private void NewuserActionPerformed(java.awt.event.ActionEvent evt) {                                       
    new NewUser().setVisible(true);
    NewUser newuser = new NewUser();// TODO add your handling code here:
        * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new RaceScreen().setVisible(true);
        // Variables declaration - do not modify                    
        private javax.swing.JLabel Heading;
        private javax.swing.JButton Login;
        private javax.swing.JButton Newuser;
        private javax.swing.JButton UserScreenExit;
        private javax.swing.JButton UserScreenHelp;
        // End of variables declaration                  
    // Program 2
    * Login.java
    * Created on September 7, 2008, 11:35 AM
    package cargame;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    * @author  DieBlouBaba
    public class Login extends javax.swing.JFrame implements ActionListener {
        String pass2, name2;
       String un;
    String pa;
          RaceScreen racesreen = new RaceScreen();
        /** Creates new form Login */  
        public Login() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
        private void initComponents() {
            Username = new javax.swing.JLabel();
            Password = new javax.swing.JLabel();
            LoginOK = new javax.swing.JButton();
            LoginCancel = new javax.swing.JButton();
            Usernamel = new javax.swing.JTextField();
            Passwordl = new javax.swing.JTextField();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Log In");
            Username.setText("Username:");
            Username.setAutoscrolls(true);
            Username.setBorder(javax.swing.BorderFactory.createEtchedBorder());
            Password.setText("Password:");
            Password.setBorder(javax.swing.BorderFactory.createEtchedBorder());
            LoginOK.setText("OK");
            LoginOK.addActionListener(this);
            LoginCancel.setText("Cancel");
            Usernamel.setNextFocusableComponent(Usernamel);
            Usernamel.setSelectionEnd(1);
            Usernamel.setSelectionStart(10);
            Passwordl.setSelectionEnd(1);
            Passwordl.setSelectionStart(10);
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(Password, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                        .add(Username, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                            .add(LoginOK, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 89, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                            .add(LoginCancel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                            .add(39, 39, 39))
                        .add(layout.createSequentialGroup()
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, Passwordl)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, Usernamel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE))
                            .addContainerGap())))
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(Usernamel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(Username, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 19, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(Password, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE)
                        .add(Passwordl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(LoginCancel)
                        .add(LoginOK))
                    .addContainerGap(20, Short.MAX_VALUE))
            pack();
        // Code for dispatching events from components to event handlers.
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == LoginOK) {
                Login.this.LoginOKActionPerformed(evt);
        }// </editor-fold>                       
    private void LoginOKActionPerformed(java.awt.event.ActionEvent evt) {                                       
    runner();
    JOptionPane.showMessageDialog (null, racesreen.un2, "Database Error", JOptionPane.ERROR_MESSAGE);
         JOptionPane.showMessageDialog (null,  racesreen.pa2, "Database Error", JOptionPane.ERROR_MESSAGE);LoginCheck checking = new LoginCheck();      
    LoginCheck logincheck = new LoginCheck();
    logincheck.Users();
         public void runner ()
         Usernamel.select(0, 10);
        String un = new String();
        un = Usernamel.getText(); 
         Passwordl.select(0,10);
          String pa = new String();
         pa = Passwordl.getText();
    public void Userlogin ()
        runner();
        // Variables declaration - do not modify                    
        private javax.swing.JButton LoginCancel;
        private javax.swing.JButton LoginOK;
        private javax.swing.JLabel Password;
        private javax.swing.JTextField Passwordl;
        private javax.swing.JLabel Username;
        private javax.swing.JTextField Usernamel;
        // End of variables declaration                  
    //Program 3
    package cargame;
    import java.awt.Toolkit;
    import java.sql.*;
    import javax.swing.*;
    public class LoginCheck
        int repeat = 1;
        public static int i = 1;
        public static Statement stm;
        public static ResultSet rst;
        public static Connection cnt;
        public static final String driver =
            "sun.jdbc.odbc.JdbcOdbcDriver";
        public static final String url =
            "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=";
        String path = System.getProperty ("user.dir", "") + "\\Cars.mdb";
        String tempname[] = new String [2];
        String temppass[] = new String [2];
        String usernamefromdb, passwordfromdb, namel, passl;
        // Login login = new Login();
        Login login = new Login ();
        RaceScreen racesreen = new RaceScreen ();
        int y = 0;
        int t = 0;
        public LoginCheck ()
            super ();
        //Making the connection
        @ SuppressWarnings ("static-access")
            public void makeConnection ()
            try
                Class.forName (driver);
                cnt = DriverManager.getConnection (url + path);
            catch (Exception ex)
                Toolkit q = Toolkit.getDefaultToolkit ();
                q.beep ();
                JOptionPane jop = new JOptionPane ();
                jop.showMessageDialog (null, " Cannot Connect\n", "Database Error"
                        , JOptionPane.ERROR_MESSAGE);
        //Closing the Connection
        @ SuppressWarnings ("static-access")
            public void closeConnection ()
            try
                cnt.close ();
            catch (Exception ex)
                Toolkit q = Toolkit.getDefaultToolkit ();
                q.beep ();
                JOptionPane jop = new JOptionPane ();
                jop.showMessageDialog (null, " Cannot Close\n", "Database Error"
                        , JOptionPane.ERROR_MESSAGE);
        public void Userdetails ()
            try
                stm = cnt.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE
                        , ResultSet.CONCUR_READ_ONLY);
                rst = stm.executeQuery ("Select * FROM Users");
                while (rst.next ())
                    usernamefromdb = rst.getString ("Username");
                    passwordfromdb = rst.getString ("Password");
                    JOptionPane.showMessageDialog (null
                            , usernamefromdb + passwordfromdb
                            , "User Logged in"
                            , JOptionPane.WARNING_MESSAGE);
                tempname [t] = usernamefromdb;
                temppass [t] = passwordfromdb;
                t = t + 1;
                for (t = 0 ; t < 2 ; t++)
                    System.out.println (tempname [t] + "\n" + temppass [t]);
                System.out.print (tempname + "    " + temppass);
            catch (Exception ex)
                System.out.println (ex);
        public void Users ()
            login.Userlogin ();
            Userdetails ();
            JOptionPane.showMessageDialog (null
                    , login.un + " g "
                    , "User Logged in"
                    , JOptionPane.WARNING_MESSAGE);
            JOptionPane.showMessageDialog (null
                    , login.pa
                    , "User Logged in"
                    , JOptionPane.WARNING_MESSAGE);
            if ("Eben".equalsIgnoreCase ("Eben"))
                if ("Eben".equalsIgnoreCase ("Eben"))
                    JOptionPane.showMessageDialog (null
                            , login.un + " has logged in"
                            , "User Logged in"
                            , JOptionPane.WARNING_MESSAGE);
                else
                    JOptionPane.showMessageDialog (null
                            , "Sorry, wrong password.", "Password"
                            , JOptionPane.ERROR_MESSAGE);
                    Runtime.getRuntime ().exit (0);
            else
                JOptionPane.showMessageDialog (null
                        , "Sorry, User does not exist", "User"
                        , JOptionPane.ERROR_MESSAGE);
        public static void main (String[] args)
    }It's done on Netbeans 6.1, so wont work in Ready

  • Namespace prefix in created DOM document string

    Hello world,
    I am creating a DOM document using the standard JAXP APIs. The document is not parsed from anywhere, just created using the DOM API factory methods. This document is a SOAP message with the SOAP envelope, header and body elements. Now I need to have this document transformed to an XML string.
    I can manage all this. However, I want to have the SOAP namespace set for the SOAP elements, and I want it set using a prefix (such as "SOAP-ENV" or "env" as in the example below). I have set the envelope, header and body element namespaces to the soap namespace. The rest of the elements inside header and body I have set to null namespace. I want them without any prefix (and what namespace will that be then, default?).
    The problem is, when I transform the document to a string, the namespace is set on the envelope without a prefix, and not on the header or body. I guess this is because the child elements will all inherit the namespace? I tried with xalan and saxon.
    Here is an example of output that would look like what I want:
    <env:Envelope xmlns:env="http://www.w3.org/2002/12/soap-envelope">
    <env:Header>
      <foo>hello</foo>
    </env:Header>
    <env:Body>
       <bar>is open</bar>
    </env:Body>
    </env:Envelope>Here is an example of output that looks like what I got:
    <Envelope xmlns="http://www.w3.org/2002/12/soap-envelope">
    <Header>
      <foo>hello</foo>
    </Header>
    <Body>
       <bar>is open</bar>
    </body>
    </Envelope>So so what am I doing wrong, how should I do it? If my rambling makes no sense, even an example of constructing output like the example of what I want would solve this.. :)
    Thanks,

    You could just create the an attribute like this:
    root.setAttribute("xmlns:env", "http://www.w3.org/2002/12/soap-envelope"); where root is the Envelope element.
    Hello world,
    I am creating a DOM document using the standard JAXP
    APIs. The document is not parsed from anywhere, just
    created using the DOM API factory methods. This
    document is a SOAP message with the SOAP envelope,
    header and body elements. Now I need to have this
    document transformed to an XML string.
    I can manage all this. However, I want to have the
    SOAP namespace set for the SOAP elements, and I want
    it set using a prefix (such as "SOAP-ENV" or "env" as
    in the example below). I have set the envelope,
    header and body element namespaces to the soap
    namespace. The rest of the elements inside header and
    body I have set to null namespace. I want them
    without any prefix (and what namespace will that be
    then, default?).
    The problem is, when I transform the document to a
    string, the namespace is set on the envelope without
    a prefix, and not on the header or body. I guess this
    is because the child elements will all inherit the
    namespace? I tried with xalan and saxon.
    Here is an example of output that would look like
    what I want:
    <env:Envelope
    xmlns:env="http://www.w3.org/2002/12/soap-envelope">
    <env:Header>
    <foo>hello</foo>
    </env:Header>
    <env:Body>
    <bar>is open</bar>
    </env:Body>
    </env:Envelope>Here is an example of output that looks like what I
    got:
    <Envelope
    xmlns="http://www.w3.org/2002/12/soap-envelope">
    <Header>
    <foo>hello</foo>
    </Header>
    <Body>
    <bar>is open</bar>
    </body>
    </Envelope>So so what am I doing wrong, how should I do it? If my
    rambling makes no sense, even an example of
    constructing output like the example of what I want
    would solve this.. :)
    Thanks,

  • JTextField and Strings

    I have a problem with using a JTextField in an IF statement. What im trying to achieve is that when the variable "TOLASuser" (JTextField) has a blank text (null) the IF statement then goes on to tell the user through a JTextArea that a null entry is not valid. The problem i'm having is that the IF statement does not read the TOLASuser.getText() as null when there is nothing entered into it, and goes straight on to the else clause.
    Do I need to add anything additional to the code prior to using the IF statement. Below is my code.
    This is only a small simple program if the entire source code is required I can provide it.
    private void BtnValidateActionPerformed(java.awt.event.ActionEvent evt) {                                           
    ConsoleView.append(TOLASuser.getText() + '\n');
    String User = TOLASuser.getText();
    if(User == null)
    ConsoleView.setForeground(Color.red);
    ConsoleView.append("You must enter your TOLAS username");
    else
    LblInputpath.setText("\\" + "\\adrsydtolastest\\TOL_USR_DIR\\" + TOLASuser.getText() + "\\RUN\\DTOPLAB.txt");
    LblOutputpath.setText("\\" + "\\adrsydtolastest\\PAST_IN_RDY\\" + "TO891.CAF");
    ConsoleView.setForeground(Color.red);
    ConsoleView.append("PLEASE CHECK THE INPUT AND OUTPUT PATH BEFORE EXECUTING" + '\n');
    BtnGo.setEnabled(true);
    }

    Thank you very much for you help. the use of a new string variable initialised as "" and the use of the equals() methods works perfectly.
    below is my new code. not that you need to see it, i just want to make sure i used the CODE tags properly.
    Thanks again.
    private void BtnValidateActionPerformed(java.awt.event.ActionEvent evt) {
    String Varify = "";
    String User = TOLASuser.getText();
    if(User.equals(Varify))
    ConsoleView.setForeground(Color.red);
    ConsoleView.append("You must enter your TOLAS username");
    else
    LblInputpath.setText("\\" "\\adrsydtolastest\\TOL_USR_DIR\\" TOLASuser.getText() "\\RUN\\DTOPLAB.txt");
    LblOutputpath.setText("\\" "\\adrsydtolastest\\PAST_IN_RDY\\" "TO891.CAF");
    ConsoleView.setForeground(Color.red);
    ConsoleView.append("PLEASE CHECK THE INPUT AND OUTPUT PATH BEFORE EXECUTING" + '\n');
    BtnGo.setEnabled(true);
    }

  • String & Int in Bean

    Hi,
    i'm building a webapp to simply allow the user to enter his or her details which will be submitted with all the details stored in the bean. When deciding to either make properties such as age or telephone number as string or int in a bean, i read somewhere that it is a rule of phumb to set these properties as Strings as they are easier to validate. If that is the case, if i create a property of String age with it's corresponding getter and setter method i.e
    public void setAge(String n) {
        age = n ;
    public String getAge()
       return age;
    doing something like the above would not convert the value into an int which is what i would like to do. Therefore, i was thinking of doing the following in my bean class:
    package beans ;
    public class Person
    private int age ;
    // Constructor
    public Person() {
        age = 0 ;
    public void setAge(int n) {
        age = n ;
      public void setAge(String s) {
        try {
          age = Integer.parseInt(s) ;
        catch (NumberFormatException e) {}
      public int getAge() {
        return age ;
      }doing the above would i think be more convenient. Would that be the better way do you think?
    cheers

    BigDaddyLoveHandles wrote:
    raychen wrote:
    There's nothing wrong with what you are doing, however.I disagree. First that code doesn't belong in a bean. An then it has to be dupilcated across every bean and every "int" property. Plus I disagree with the way it swallows formatting errors.BigXXXXXwhatever...... what do you mean by that code does not belong in the bean. I've seen my example duplicated in many exampls and in books. I'm not to concerned if it has to be duplicated in every bean and int, it's not what i was asking.
    In terms of the fomatting errors, what errors? Do i need to correct something?
    Thanks for your input raychen.
    Edited by: nvidia1 on Jan 6, 2009 12:19 AM

  • JSP Strings, Ints converting

    I'm sure this sort of thing has been asked but i cant find it in the forums.... I'm trying to read in a string from a form and then convert it to an int so that i can use it in a select statement so i can compare it to a field declared as "Number" in the Access Database.
    String sess = request.getParameter("num"); //num comes from form
    int eventNum = Integer.parseInt(sess);
    //connected ot the database
    String query = "SELECT * FROM EVENT WHERE event_id = 'eventNum' ";
    ResultSet result = stmt.executeQuery(query);
    //event_id is a number in the database
    Its saying "Data type mismatch in criteria expression"
    Thanking you in advance,
    Brian

    Since you are building a string as query, you don't need to convert it
    String sess = request.getParameter("num"); //num
    String query = "SELECT * FROM EVENT WHERE event_id ='eventNum' ";
    ResultSet result = stmt.executeQuery(query);This error "Data type mismatch in criteria" comes from event_id = 'num'
    event_id is numeric, so it should not contain quotes in the sql statement
    this will do it:
    String query = "SELECT * FROM EVENT WHERE event_id =" + sess

  • String - int

    i want to convert a string var into int var?
    how is that possible in jsp?
    thank you!

    int intvar = Integer.parseInt(StringVar);

  • Error  executeUpdate(String,int)

    i try execute follow source and obtain error:
    Exception in thread "main" java.lang.NoSuchMethodError
    at ProbaInsertId.getKey(ProbaInsertId.java:54)
    at ProbaInsertId.main(ProbaInsertId.java:19)
    import java.util.*;
    import java.io.*;
    import java.sql.*;
    public class ProbaInsertId
    public static void main(String args[])
         getKey();
    public static void getKey(){
         int key = 0;
              String nume="zzz";
              String prenume="fff";
              try{
                   Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
              catch(Exception e) {
                   e.printStackTrace();     
                   System.out.println("Eroare incarcare driver!\n" + e);
              Connection conn = null;
              try{
              conn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://mother:1433;DatabaseName=db", "mihai", "mihai");
    String sqlQueryInsert = "INSERT INTO proba (nume, prenume) " +
                             "VALUES(nume, prenume)";
    Statement sqlStatementInsert = conn.createStatement();
                   sqlStatementInsert.executeUpdate(sqlQueryInsert,sqlStatementInsert.RETURN_GENERATED_KEYS);
    ResultSet rs = sqlStatementInsert.getGeneratedKeys();
    if( rs.next() ){
         key = rs.getInt(1);
                        System.out.println(key);
                        sqlStatementInsert.close();
                        conn.close();
              catch(Exception e) {
                   e.printStackTrace();     
                   System.out.println("Eroare select 2!\n" + e);

    Sounds like that JDBC driver doesn't support getting auto-generated keys. - MOD

  • Sending more than one original document via INT

    Hi all,
    I've created a DIR with 2 Original Documents uploaded in.
    When I start the distribution (Distribution type --> INT) I receive the e-mail without any attachment.
    Otherwise, if I upload a single original document in the DIR, I get the correct e-mail (with the attachment).
    Suggestions?
    Thanks,
    Marco.
    Edited by: Marco Cariello on Jul 22, 2009 2:53 PM

    Hi,
    this customizing setting was already set in DC10
    Any other suggestions?
    BR
    Marco
    Edited by: Marco Cariello on Jul 23, 2009 1:02 PM

  • JTextField document model

    Hi,
    I have a JTextField field, which is supposed to be read only field to show time.
    My application gets from server a long value, which represents the time.
    This JTextField field shows the time (from server) in format mm:hh:ss (need to convert the long value to the format).
    My question is:
    Which document model should I use and how? I don't find a good example for that.
    Thanks

    I have a JTextField field, which is supposed to be read only field to show time.I would say that typically you would use a JLabel for this. Then you just use the setText() method.

  • JTextField Document validation

    What is the best way to use Document to validate a textfield that will only accepts numbers between 1 and 30.

    Lets say there is a situation where we really need to prevent users from typing numbers out of range (instead of showing an error message afterwards). I looked at the tutorial and there is an example on how to use DocumentFilter to restrict input to Integers. I tried to adapt it to do range checking. I was successful in enforcing max value but I can't get it to enforce min value. If the min value is 2 and if the user types 11 then DocumentFilter.insertString is called twice. First with just 1 and then with 11. Is there someway to stop insertString from being called until the user is done typing? I must be missing something obious.

Maybe you are looking for

  • Problem in Logic for Customer Ageing Report

    Hi, I am developing a Customer Ageing Report in which i am facing a problem i.e. i am taking tables BSID,BSAD in which i ham taking the open items first and then i am using for all entries in it on the open items and i had debugged it and data pickin

  • [JS CS3] Find paragraphs that contain a single Style override

    Given a document with consistently applied paragraph styles. I need to locate all the paragraphs in the document that contain a paragraph style override of the left indent. All other style overrides can be ignored. I see in the DOM how to clear overr

  • Workflow scenarios for FS-CD module

    Hi All I am working for FS-CD module for workflow and I am working on FPY1 transaction code for triggering some workitems based on the clients requirements. Could anyone provide me some workflow scenarios for the above said transaction and also for t

  • FCE 3 Project in FCP 5

    That's it. Can my buddy, using FCP 5 open my FCE 3 project? If so, will anything be "lost" in the translation? Thanks

  • Want to Know more about Views, Viewset and Viewarea.

    Dear all, We are into IC Webclient configuration. I want to know that,  what are views, viewsets and viewarea with examples. What is the relation between them? How can I add or modify a view, viewset or viewarea in IC Webclient? Where these views, vi