kei hosima

Greenhorn
+ Follow
since Feb 23, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by kei hosima

Hi!
I'm working on this for long time, and I have out of idea whatelse I should do to fix my code.
Hope someone could give me some adivce.
What I'm trying to do is this:
Define non-public class named MyLabel that encapsulates a customized Label component. It should extend the Label class and implement the Runnable interface in order to be run as a thread. A MyLabel object must display text that changes its color and font at a specified interval. If an attempt is made to set a null text or an interval that is less than zero, the corresponding "set" method must throw an Exception object having an appropriate error message.
The following is the part of my code.
[code]
private MyLabel myLabel;public void init() { myLabel = new MyLabel();// getting error message. don't know what to put after MyLabel. myLabel.setFont(new Font ("Serif", Font.PLAIN, 12));
myLabel.setForeground(Color.red); myLabel.setBackground(Color.black); c.gridx=0;
c.gridy=1;
c.gridheight=1; c.gridwidth=GridBagConstraints.REMAINDER;
add(myLabel, c);
public void actionPerformed(ActionEvent e) { // if statemnets......
else
{
try{
m.put(new String(nameField.getText()),
new Employee(nameField.getText(), Double.parseDouble(payRateField.getText().trim())));
msg.setText("The employee has been added to the collection.");
checkLabel(myLabel);
}catch (Exception err){
System.out.println(err.getMessage());
}}}

public void checkLabel(MyLabel myLabel)throws Exception{
msg.setText("LabelTEST");}
class MyLabel extends Label implements Runnable{
int interval;
String myLabel;
MyLabel (String myLabel, int blinkSpeed){
Thread t = new Thread (this);
t.start();}
public void run() {
for(int i=0; i<100; i++) {
try{
Thread.sleep((int)(Math.random() * 1));
} catch( InterruptedException e ) { System.out.println("Interrupted Exception caught");
}
Color oldForeground = getForeground(); setForeground(getBackground());
setBackground(oldForeground);
}}
public void setMsg (String newMsgLabel){ myLabel = newMsgLabel;
throw new NullPointerException();}
public void setInterval (int newInterval){ interval = newInterval;
throw new NumberFormatException();}}

myLabel doesn't do anything. It does not blink at all.
What am I doing wrong?
Sorry for this long question... and thank you for reading everything.
Please give me some adivce.
I would very very appreciate your help!
Thanks in advance.
20 years ago
thank you very much for your reply.
I changed to
msg.setText("We found " + m.get(nameField.getName()));
I'll try to see if it would work or not.
20 years ago
Hello.
I can't figure out why the following code is not working. Hope someone could help me.
First one is 'remove( )'
I want to check if the nameField is in the collection or not.
If it is in the collection, I want to remove it from the collection.
I'm using SortedMap m = new TreeMap();

I have the following error message
"method remove(java.lang.String, project06.App.Employee) not found in interface java.util.SortedMap"
the second is "firstKey"
I want to make sure if the collection is empty or not. If it's empty, show an error message. if it's not empty, show the first record in the collection.

The following is the error message I'm getting:
"method firstKey(java.lang.String, <any> not found in class project06.App"
Finally, get( ).
I want to find a specific record from the collection.
The following is my code.

The following is the error message
"method get(java.lang.String, double) not found in interface java.util.SortedMap"
I would appreciate any suggestion/help/advice.
Thanks in advance.
[ March 31, 2003: Message edited by: Cindy Glass ]
20 years ago
Hi Maulin.
Thank you very much for your suggestion.
I'll try to develop my code based on your suggestion.
thank you for your time.
Regard
Kei
21 years ago
Hello.
I'm using TreeMap for a collection.
In a single source file named App.java, there is an Employee class to encapsulate employee data and an App class defining an applet to maintain a collection of Employee objects.
private instance variables for name(string) and pay rate (double) are in the Employee class.
There is an Add button.
I want to triggers the construction of an Employee object having the currently displayed name and pay rate and the addition of the object to the collection when clicking 'Add' button.
The following is the part of my code.
<CODE>
SortedMap m = new TreeMap();
addBtn = new Button ("Add");
addBtn.setBackground(Color.red);
addBtn.setForeground(Color.black);
addBtn.addActionListener(
new ActionListener() {
public void actionPerformed (ActionEvent e){
// check to see if name field is empty or not.
if (e.getSource().equals(nameField)){
if ((nameField.getText()).equals("")){
msg.setText ("Please Enter an Employee Name");
}}
// check to see if name field is empty or not.
if (e.getSource().equals(payRateField)){
if ((payRateField.getText()).equals("")){
msg.setText ("Please Enter a Pay Rate");
}}
// check to see if the name is already in the collection or not.
// If it's not in the collection, add the record.
if (m.containsKey(nameField.getText())){
msg.setText ("The employee is already in our collection");
}
else {
// add the employee record.
m.put(name, new String(setName));
}
</CODE>
This is not working at all.
I would appreciate any suggestion/help/advice.
Thank you very much in advance.
21 years ago
There is a CardLayout layout manager name clay and has been populated with 5 components whose identifiers are "A", "B", "C", "D", "E".
I don't know the order in which the components were added to the container.
I know, however, that the component with the identifier "B" is not the first component.
In such a case, how could I display the component that was added to the container prior to the one having the identifier of "B"?
I know there are 4 possible methods I could use
first(), last(), next(), and previous().
But how? How could I display the component that was added to the container prior to "B" if I don't know the order of the container?
I would appreciate your suggestion/advice/help.
Thanks in advance.
21 years ago
Michael
Thank you so much for your help.
I'll try your code.
thank you!
kei
21 years ago
Hello.
I hope someone could help me.
How could I erase a text field's contents as soon as the user presses the CTRL key while the text field has focus?
"data" is a properly instantiated TextField object with class-wide scope and the current object as its registered KeyListener.
public void keyTyped (KeyEvent e) {
TextField t = data.getText();
t.clearRect (0, 0, data.getWidth(), data.getHeight());
}
the above code won't work.
I would really appreciate your help.
Thanks in advance.
21 years ago
Oh... that's true.
What was I thinking...
I changed to 'convButton'.
I'm using JBuilder 4 to compile the code.
I guess I need to think the if statement little bit more.
thank you very much for you help!
21 years ago
Hi. I figured out the pop-up frame part.
Now, when I click a button, nothing happen.
I mean NOTHING.
could someone please give me advice.
Thank you

Any suggesion/advice/hints would be greatly appriciated.
Thank you in advance.
21 years ago
Well, I figured it out, and it works now.
thanks
21 years ago
Hello.
Could someone help me to fix my pop-up frame, please.
There is a "Help" menu with an "About" menu item.
When a user click 'About', pop-up frame should be displayed. When I click 'About', 2 pop-up frames are displayed. one is empty with correct frame size the other one is only bar.
the follwoign is my code.

There is actionPerformed method as follow

What am I doig wrong?
I would very appriciate your help.
Thank you
21 years ago
This program is to perform conversions between F and C temperatures. Input Components are input temperature(textfield), Output precision(a choice), conversion to be performed (a group of checkbox objects), output text size(scrollbar), Calculate(button), and a help menu with an about menu item.(displaying pop-up frame).
Output component is resulting temperature(Label).
I know the code would be placed in the adjustmentValueChanged() method, but I don't know how I could change the label's font (to be larger or smaller) based upon the scrollbar.
The pop-up frame, when I click the menu item, the both main frame and menu item frame pop up. How could I chage it so that only menu item frame will pop up? Also, the button is not working. I mean, the whole program is not working... it doesn't calculate.. do anything...
Could someone please check my code below and let me know what I should do.
thanks

thank you.
21 years ago