Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!

Nadinha Jovan

Greenhorn
+ Follow
since Feb 13, 2004
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 Nadinha Jovan

I downloaded the emulator and installed midp-java runtime environment to it (i can see the Java HQ icon on it). I installed the MIDlet I developed. When I attempt to run it, it starts and allows me to select the midlet I want to run. Upon selection, I receive the following error "Unable to load class javax.microedition.lcdui.CustomItem. I am not sure why is this happening since CustomItem is a part of MIDP implementation. When I ran Java HQ, it says that its version is 1.0. Does this mean that I installed midp 1.0? If that is so, I guess I need to install midp for palm os 2.0.

Thanks for your help.
19 years ago
I need to play a sound when a button is selected. I am using the following code to do it:

JRadioButton soundBT = new JRadioButton();
.
.
.
soundBT.addActionListener(new ActionListener() {
public void actionPerormed(ActionEvent e) {
if (soundBT.isSelected()) {
URL soundUrl = getClass().getResource(EOF_SOUND);
AudioClip audioClip = Applet.newAudioClip(soundUrl);
audioClip.play();
}
}
});

However, the sound is inconsistent. Sometimes it is played, other times it is played partially, and sometimes it is not played at all. Any suggestions would be helpfull. Thanks.



}
19 years ago
You can subclass Document and in it provide implementation for the insertString model. In this model you can control users input. Here is an example of Document allowing integers only to be entered in a text field.

import java.awt.Toolkit;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

public class IntegerDocument extends PlainDocument {

public void insertString(int offs, String str, AttributeSet a)
throws BadLocationException {

char[] source = str.toCharArray();
char[] result = new char[source.length];
int j = 0;
for (int i = 0; i < result.length; i++) {
//it is ok for the first char to be '-'
if (Character.isDigit(source[i]))
result[j++] = source[i];
else if (offs==0 && i==0 && source[i]=='-')
result[j++] = source[i];
else
Toolkit.getDefaultToolkit().beep();
}
super.insertString(offs, new String(result, 0, j), a);
}

}


And here is the IntegerTextField class and set its default document model to be the document model class you created.


import java.awt.Toolkit;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;
import javax.swing.JTextField;
import javax.swing.text.Document;
import mq.psy.jwatch.ui.swing.document.IntegerDocument;

public class IntegerTextField extends JTextField {

private NumberFormat integerFormatter;

public IntegerTextField(int columns) {
super(columns);
integerFormatter = NumberFormat.getIntegerInstance(Locale.US);
integerFormatter.setParseIntegerOnly(true);
}

public IntegerTextField() {
this(0);
}

protected Document createDefaultModel() {
return new IntegerDocument();
}

}
19 years ago
Here is the code I am using to scroll JTable to its last cell and to make that cell visible. For some reason however, that cell is selected but the table does not scroll to it to make it visible. Can anyone help and tell me what I am doing wrong?

JTable table = codeEntryPN.getCodeDescriptionTable();
TableModelDataCapture tableModel = (TableModelDataCapture)table.getModel();

//adds a row of data to model to the end and fires row inserted
tableModel.addDummyRow();
int lastRow = tableModel.getRowCount() - 1;
table.setRowSelectionInterval(lastRow, lastRow);

//makes the newly added row visible
table.scrollRectToVisible(table.getCellRect(lastRow, 1, true));

thanks
19 years ago
I have a JTextField and a JButton. The user can either type the text in the text field or he can click the button and select the folder, whose name will be then entered as the text of the text field using setText method. In either one of the two cases I want to set a variable _userSetResultFolder = true.
However, there is also another text field in the panel that will set the result folder text field if it is not set by the user (_userSetResultFolder = false), to the value of this folder + /results, in this case of course I want _userSetResultFolder to remain false.

How can I ensure that even when the user types into the result folder text field rather than using the result folder button, the _userSetResultFolder gets set to true.

Thanks.
19 years ago
I am adding 3 components to a panel using grid bag layout. I would like the viewPN (see code below) to resize when the application window is resized but I cannot figure out how to do that. I want the viewPN to initially have size 1 row and 1 column and to accordingly change its size horizontally if the window is expanded. Here is the code I currently have in place. Thanks.
this.setLayout(gridBagLayout1);
this.add(durationPN, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 2, 0, 10), 0, 0));
this.add(viewPN, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 10, 0, 2), 0, 0));
this.add(editRowPN, new GridBagConstraints(0, 1, 3, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 2, 2, 2), 0, 0));
Thanks for your help.
20 years ago