Solved

How to set format to TextField and get data from the database to choice box

Posted on 1998-07-23
10
389 Views
Last Modified: 2011-05-06
1.       Could you please help me write an application program to set format to TextFields:  
          phone number "(###)#### - ####"), time "00:00:00",  and get data such as phone number
          and address (State is a choice box in the user interface) from the "registration" table in
          database MOCS.mdb(c:/DB/MOCS.mdb)?
          My system data source name is "MyProject", and the driver is "Microsoft Access
          Driver(*.mdb).
         
2.      What are problems in the following codes?

              //Declare a public variables' class
              import java.awt.*;
              public class variable
              {
                  TextField Course1, Course2;
              }
0
Comment
Question by:AmyS
  • 4
  • 3
  • 3
10 Comments
 

Author Comment

by:AmyS
ID: 1228012
Edited text of question
0
 
LVL 1

Expert Comment

by:dryang
ID: 1228013
Can't answer the first one but the second is this:

1) If you want the data available for all methods to read and access

              public class variable
                 {
                     public static TextField Course1, Course2;
                 }

2) Or to encapsulate the data and use methods to access them (safer way)

              public class variable
                 {
                     TextField Course1, Course2;
                     
                     public TextField getCourse1()
                     {
                       return Course1;
                      }

                     public TextField getCourse2()
                     {
                       return Course2;
                      }
                  }

if you want to do it using the second way, remember to have methods to write to the TextFields!

cheerios
0
 
LVL 1

Expert Comment

by:dryang
ID: 1228014
ARRRRRRRRRRRRRGH! I'm getting senile

to answer your second question of what's wrong
- your data is not accessible to all mehods and classes. Any variables without the private, protected or public tags are consedered 'friendly' to the class itself (which means extremely unfriendly to others!)


0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 2

Expert Comment

by:threshold
ID: 1228015
It's not easy for your first question, here is my solution:
  Make a Class to implement TextListener, and use TextField.addTextListener(...) to let your class can receive TextEvent from TextField.
  When your Class receives the TextEvent (when the text of TextField is changed),
    the method textValueChanged(...) will be actived.
  So, you should write some code in textValueChanged() of your Class to check/modify content of TextField with your pattern. You need to save legal content in every time.

  The another way is to create your own awt component that can fire KeyEvent and check current context with patterns.

  If you know about java bean, you can create your own bean for this purpose!

  Check the document of JDK1.1.x and java.sun.com, there are many examples and documents about Bean, and Event model.
0
 

Author Comment

by:AmyS
ID: 1228016
Thank Dryang for answering my second question. I should give him/her points, but I don't
know how I can do in this window. Sorry!
Actually, Dryang's answer for the first question was not clear. I hope somebody can help me write an application code for the first question ( at least, to solve the problem that
how to get data such as phone number and address (State is a choice box in the user interface) from the "registration" table in database MOCS.mdb(c:/DB/MOCS.mdb)?
My system data source name is "MyProject", and the driver is "Microsoft Access
Driver(*.mdb)". ).
0
 
LVL 1

Expert Comment

by:dryang
ID: 1228017
Its ok, AmyS. anyway, I was answering the second question only and did not touch the first question at all :) .
0
 
LVL 2

Expert Comment

by:threshold
ID: 1228018
Oh, To Know how to get data from .mdb file is a long story.
First, you should know about JDBC, and ODBC. then you can access .mdb file via JDBC-ODBC...
second, turn on the option 'view the system table' of access. Then you can get the table definition from .mdb file and read the input mask into JAVA.

0
 
LVL 2

Expert Comment

by:threshold
ID: 1228019
sorry, wrong click by me. The last post should be a comment, not answer...
0
 

Author Comment

by:AmyS
ID: 1228020
I have spent one more week to wait somebody help me write a simple program
to solve my first question. Now what should I do for the points?

0
 
LVL 1

Accepted Solution

by:
dryang earned 100 total points
ID: 1228021
Thanks AmyS
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
object oriented programming comparison 5 77
xampp tool 12 56
throw exception 21 58
Problem to Alipay 10 48
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to implement Singleton Design Pattern in Java.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question