我在 java 站点上找到了一个关于如何制作对话框窗口的网页,但是当我尝试它时它不起作用。该网站说键入:
JOptionPane.showMessageDialog(frame, "Window text.");
Run Code Online (Sandbox Code Playgroud)
我只是想用一些文本和一个确定按钮来制作一个窗口,但是当我输入它时,我的 Eclipse IDE 想让我为 JOptionPane 导入一些东西,在我这样做之后,它说“框架” 部分不正确,即“无法解析为变量”。我在这里做错了什么?
我是一名初学程序员,我正在尝试编写一个简单的程序,询问一个问题,然后在输入对话框中输入"A","B"或"C"的形式提示您回答该问题,但没有出现对话框.其他一切似乎都很好.
这是我的代码:
package homework;
import javax.swing.JOptionPane;
public class Quiz {
public static void main(String[] args)
{
int x = 0;
String[] quizQuestion = {"What is the color of the sky?", "What is the
color of the sea?", "What is the color of the earth?"};
int score = 0;
String correct = "You are correct";
String incorrect = "You are incorrect";
String playerAnswerString = " ";
playerAnswerString.toUpperCase();
char playerAnswer = playerAnswerString.charAt(0);
JOptionPane.showMessageDialog(null, "Test Your Knowledge!");
JOptionPane.showMessageDialog(null, "Select an answer to the …
Run Code Online (Sandbox Code Playgroud) 我需要弹出一个对话框并获得用户确认.我希望这个dailog应该始终排在最前面,直到用户选择是或否选项.下面是我写的程序,但现在如何获得用户选择的选项..即是或否..?
JFrame parent = new JFrame();
JOptionPane optionPane = new JOptionPane("DO you want to continue?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
JDialog dialog = null ;
dialog = optionPane.createDialog(parent, "Next Job process");
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
Run Code Online (Sandbox Code Playgroud) 我试图将答案放在一个变量中,但我遇到了这个错误:
double p1;
String text = JOptionPane.showInputDialog("Type the grade of p1");
p1 = double.parseDouble(text);
Run Code Online (Sandbox Code Playgroud)
当我使用double.parseDouble(text)
我进入"double cannot be dereferenced"
Netbeans ID.E
我究竟做错了什么?
代码1:
public static JFrame frame = null;
public myClass(JFrame frame1)
{
initComponents();
frame = frame1;
String result = JOptionPane.showInternalInputDialog(
frame.getContentPane(), "Sample");
}
Run Code Online (Sandbox Code Playgroud)
代码2:
public static JFrame frame = null;
public myClass(JFrame frame1)
{
initComponents();
frame = frame1;
sampleMethod();
}
public static void sampleMethod()
{
String result = JOptionPane.showInternalInputDialog(
frame.getContentPane(), "Sample");
}
Run Code Online (Sandbox Code Playgroud)
我希望代码1中的结果,但代码必须看起来像代码2.为什么它们有不同的结果?
我尝试运行以下代码.它编译,但抛出ClassCastException.如果有人能帮助我找出原因,我会很高兴的.
double costprice = 0;
Object[] possibilities = null;
costprice = (double) JOptionPane.showInputDialog(
alphaPOS,
"Cost Price:",
"Enter Values",
JOptionPane.PLAIN_MESSAGE,
null,
possibilities,
"");
Run Code Online (Sandbox Code Playgroud) 我做错了什么以及如何解决?我在日食上运行这个.
import java.awt.Component;
import javax.swing.Icon;
public class JOptionPane {
public static void main(String[] args) {
// JOptionPane inputs
Component parentComponent = null;
Object message = "What do you think of Hudson?";
String title = "VERY IMPORTANT!";
String choice1 = "1";
String choice2 = "2";
String choice3 = "3";
int optionType = JOptionPane.YES_NO_OPTION;
int messageType = JOptionPane.ERROR_MESSAGE;
Icon icon = null;
// JOption pane display
Object[] options = { choice1, choice2, choice3 };
int option = JOptionPane.showOptionDialog(parentComponent, message, title,
optionType, messageType, …
Run Code Online (Sandbox Code Playgroud) java ×7
joptionpane ×7
swing ×4
double ×2
casting ×1
dialog ×1
loops ×1
modal-dialog ×1
parsing ×1
window ×1