Mindy Wu

Ranch Hand
+ Follow
since Jan 12, 2001
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 Mindy Wu

I need to randomly generate x numbers from range 1 - 5 in a unique sequence.
For example:
x=20, within the set, i want to have 5 ones', 10 threes', and 2 twos', 1 fours', 2 fives' in a random sequence.
I know it is possible to achieve the about task by using a counter inside the loop. However, this is not the efficient way.
Can anyone help me out?
Thanks a lot!
16 years ago
Thank you for your help!
Also, i found the default background color is R=204, G=204, B=204.
16 years ago
Hello there,
How can i clear the background color of a JButton which current background is blue?
What is the RGB color code for the default button color?
Thanks
16 years ago
Hello Eddie,
Your help is greatly appreciated!
16 years ago
Hello All,
I have an array of buttons and each button has an icon image. I need to keep track of which button being clicked by the user. For example, if user click button[1], the event.getActionCommand() return 1. However, button[1] only has an icon, there is no label on the button, it is obvious there is nothing return.
My questions
1. how to get the icon name of the selected button
2. how to make an invisible label
my code:
for (count=1; count <=14; count++)
{
btn[count] = new JButton( rmIcon );
btn[count].setPreferredSize(new Dimension(40, 25));
btn[count].addActionListener(handler);
roomPanel.add(btn[count]);
}
How can i make the index invisible if i add the index on the button.
for (count=1; count <=14; count++)
{
btn[count] = new JButton( Integer.toString(count), rmIcon );
btn[count].setPreferredSize(new Dimension(40, 25));
btn[count].addActionListener(handler);
roomPanel.add(btn[count]);
}
Thank you!

[ March 16, 2004: Message edited by: Mindy Wu ]
16 years ago
actually, my problem a little bit more complicate than this, how to solve if x%10=8, where 8 is a reminder, 10 is the dividen, x must be less than or equal to 16.
Thanks!
[ January 19, 2003: Message edited by: Mindy Wu ]
17 years ago
Hi there, I have read through the search result of the Modulus operator and could not find the answer to my question, so, I post my question here.
In mathematic term: a = dq+r, where "a" is an integer and "d" is a dividend and q is a quotient, "r" is the remainder. In java, we can use "%" to get a reminder of a division. e.g
m=101, n=11, 101%11=2, if we just know "m=100" and the reminder (2), how can we get "n" in java?
In reality, everyone can calculte in their head and get the solution, how can I write the code in java to get the solution? e.g 101%n=2, how to solve n?
Waiting for help!
Thanks!
Mindy
17 years ago
Thank you Cindy! I am going to create different actionlistener for each set of menu item.
By the way, can i add a JButton on the menubar?
18 years ago
I created a menu with : Tools
menuitem - Add
subMenuItem - A
subMenuItem - B
menuItem - Update
subMenuItem - A
subMenuITem - B
I also registered the each menuitem with an actionListener, my question is how to get the object source name?
I try the following syntax inside the actionlistener class
JMenuItem itemSource = (JMenuItem) (e.getSource() )
System.out.println("you click: " + itemSource.getText());
return: "A" if i click A.
I actually want to get the object name instead of the source text. So i try, getActionCommand() instead of getSource(), it return to me
this: "javax.swing.JMenuItem[,1,3,101x21,alignmentX=null,alignmentY=null,border=javax.swing.plaf.metal.MetalBorders$MenuItemBorder@25fefa,flags=1056,maximumSize=,minimumSize=,preferredSi ze=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=2,right=2],paintBorder=true,paintFocus=false,pressedIcon=,rollover Enabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=Application]"
So, i want to know if there is anyway to get the object source name ("the name you define it, e.g JMenuItem menuAddA = new JMenuItem("A"), i want to get menuAddA returns)
Waiting for your reply!
Thank you very much!
Mindy
18 years ago
Thank you Cindy! I did use Thread but i forgot to use the sleep() method. It is working fine now. Thank you for your response.
Mindy
18 years ago
If you are calling another class within the try even you set the boolean value to false, the thread is never actually stops.

Can you tell me what's going on of the following code?
public void run()
{
while( threadRunning )
{
try
{
Thread.sleep( 100 );
new ClassA();
threadRunning = false;
waitDialog.show() //show an animation dialog as it is busy and it will stop when execution finishes
}
catch( InterruptedException exception )
{ }
System.out.println( "Thread Running" ); }}
if ( waitDialog.show("Executing..") == WaitDialog.CANCEL_PRESSED)
{
System.out.println("Process was cnacelled");
JOptionPane.showMessageDialog(null, "Process was cancel.", "Application", JOptionPane.ERROR_MESSAGE);
}//when i pressed cancel, the thread still alive and the action in the the new ClassA is still continue executing.
My question is how to get the execution stops when Cancel button clicks?
Thanks!
18 years ago
Should that be System.exit(0)?
18 years ago
I created a swing app and there are two buttons on the interface. When use clicks a button it will carry out some series of action, I want to use a timer object to control create a some seconds delay after each action happen because i have a run time object within my code.
My program basically do the following stuff:
Generate button : generate swing script code and save into a x.java file.
Compile Button: executing a .bat file to compile it into a x.class, and then delete the .bat file after compiling. Usually it will takes a few second to run the bat file within the app. Sometimes the bat file is being deleted before compiling.
My bat file is has only one line of code "javac xxx.java".
I hope i explained it clear enough. Can anyone give some ideas of how use a timer to delay two actions?
Thanks! I appreciate for your response!
Mindy
18 years ago
You examples are very helpful! I still have one question would like to ask: where should i set that boolean to false to make that thread stops?
Thanks!
Mindy
18 years ago