1
|
import ptolemy.gui.ComponentDialog;
|
2
|
import ptolemy.gui.Query;
|
3
|
import javax.swing.JFrame;
|
4
|
import javax.swing.BorderFactory;
|
5
|
import java.awt.Color;
|
6
|
/**
|
7
|
A test that illustrates the problem where hitting return
|
8
|
does not select the default button.
|
9
|
|
10
|
Compile and run with:
|
11
|
javac -classpath $PTII PtQueryTest.java
|
12
|
java -classpath $PTII:. PtQueryTest
|
13
|
|
14
|
Note that if the query contains a line entry, the the problem
|
15
|
occurs. If there is no line entry, then there is no problem.
|
16
|
*/
|
17
|
public class PtQueryTest {
|
18
|
public static void main(String [] args) {
|
19
|
Query query = new Query();
|
20
|
String[] options = {"water", "soda", "juice", "none"};
|
21
|
// If the first line has focus, then I have to hit a tab and then enter.
|
22
|
// Comment out the line below, recompile and then enter will have the focus
|
23
|
query.addLine("line", "What's my line?", "Groucho");
|
24
|
|
25
|
query.addRadioButtons("radio", "Radio buttons", options, "water");
|
26
|
query.setBorder(BorderFactory.createLineBorder(Color.pink));
|
27
|
ComponentDialog dialog = new ComponentDialog(null, "Test", query);
|
28
|
System.out.println("Pressed: " + dialog.buttonPressed());
|
29
|
}
|
30
|
}
|