- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先,我将提出问题,然后解释该应用程序。
如何使JFrame
表现得像JOptionPanes
? (tutorial didn't help),即[Show content >> return a value]
。另外,我需要它[Show the frame >> Ask information >> Modify an object passed as parameter to the constructor >> return something]
我已经使“确定”按钮获得了我想要的答案(在控制台中显示),但是我不知道在哪里放置return
语句
我希望功能像
public static String getAnswer(Args, Answer)
Args
,可能包含字段名称,数据类型,最大长度和
Answer
,是在用户提供信息并单击“确定”后要修改的对象
| Arg | Answer |
--------------------------------------
| Type | fldName | |
--------------------------------------
| int | Age: | 22 |
| String | Name: | Roger |
| Date | Birth: | 31/10/1989 |
JOptionPane.showMessageDialog()
等,我的问题可能会解决,但我无法解决让它满足我的需求的问题。 JOptionPane上显示的内容似乎仅限于我,而且我不知道如何保持控制力,也不知道我放入它的孩子,一切都会改变其行为。
Parameter form
)的屏幕截图,在示例中,evey项的类型为Month,答案将用其值填充。
TopPanel
,
MidPanel
和
BotPanel
):消息对话框,用户输入和命令按钮。
TopPanel
,从JScrollPane扩展并创建JEditorPane,因为它可能显示html内容
MidPanel
,从JScrollPane扩展(仅针对列表中的最后两个对话框创建),并基于一个对象创建字段,该对象作为参数输入给用户,而表单的输入则需要在java中进行了检查,因为它可以是日期,textField或基于select语句的组合框(在图中,基于对数据库的查询,一年中有12个月)。
BotPanel
具有用于java给出的答案的控件,例如参数列表或“是/否”对话框的答案。此面板随各种对话框而变化。例如对于是/否对话框,它具有“是”和“否”按钮,这些按钮将使java返回true或false,但是对于参数形式对话框,如果出现,它将返回错误消息,并且包含包含以下信息的对象用户选择了。
最佳答案
同样,您可以将任何复杂的GUI放入JOptionPane中。 JOptionPane show方法的第二个参数采用一个Object,该Object可以是任何Swing组件。例如:
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
import javax.swing.*;
import com.roots.map.MapPanel.ControlPanel;
public class ComplexDialog extends JPanel {
public static final String[] COMBO_LABELS = { "Nombre 1",
"Identificacion 1", "Fecha 1", "Empresa 1", "Nombre 2",
"Identificacion 2", "Fecha 2", "Empresa 2", "Nombre 3",
"Identificacion 3", "Fecha 3", "Empresa 3", "Nombre 4",
"Identificacion 4", "Fecha 4", "Empresa 4", "Nombre 5",
"Identificacion 5", "Fecha 5", "Empresa 5", "Nombre 6",
"Identificacion 6", "Fecha 6", "Empresa 6", "Nombre 7",
"Identificacion 7", "Fecha 7", "Empresa 7" };
public static final String[] COMBO_ITEMS = { "January", "February", "March",
"April", "May", "June", "July", "August", "September", "October",
"November", "December" };
private JTextArea textarea = new JTextArea(15, 30);
private Map<String, JComboBox> comboMap = new HashMap<String, JComboBox>();
public ComplexDialog() {
textarea.setLineWrap(true);
textarea.setWrapStyleWord(true);
for (int i = 0; i < 100; i++) {
textarea.append("This is a really large text. ");
}
JPanel comboPanel = new JPanel(new GridBagLayout());
for (int i = 0; i < COMBO_LABELS.length; i++) {
addToComboPanel(comboPanel, COMBO_LABELS[i], i);
}
int eb = 5;
setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb));
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
add(new JScrollPane(textarea));
add(Box.createVerticalStrut(5));
JScrollPane comboPanelScroll = new JScrollPane(comboPanel);
add(comboPanelScroll);
comboPanelScroll.getViewport().setPreferredSize(
textarea.getPreferredSize());
}
private void addToComboPanel(JPanel comboPanel, String labelText, int index) {
GridBagConstraints gbc = new GridBagConstraints(0, index, 1, 1, 0.2, 1.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0,
0, 5), 0, 0);
comboPanel.add(new JLabel(labelText, SwingConstants.RIGHT), gbc);
gbc = new GridBagConstraints(1, index, 1, 1, 1.0, 1.0,
GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(
0, 0, 0, 0), 0, 0);
JComboBox combo = new JComboBox(COMBO_ITEMS);
comboMap.put(labelText, combo);
comboPanel.add(combo, gbc);
}
public String getComboChoice(String key) {
JComboBox combo = comboMap.get(key);
if (combo != null) {
return combo.getSelectedItem().toString();
} else {
return "";
}
}
public String getTextAreaText() {
return textarea.getText();
}
public int showDialog() {
return JOptionPane.showOptionDialog(null, this, "Sirena",
JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null,
new String[] { "Aceptar", "Cancelar" }, "Aceptar");
}
private static void createAndShowGui() {
ComplexDialog dlg = new ComplexDialog();
int response = dlg.showDialog();
if (response == 0) {
System.out.println("JTextArea's text is:");
System.err.println(dlg.getTextAreaText());
System.out.println("Combo box selections are: ");
for (String comboLabel : COMBO_LABELS) {
System.out.printf("%20s: %s%n", comboLabel, dlg.getComboChoice(comboLabel));
}
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}
关于java - 如何使JFrame模态像JOptionPane?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8747424/
是否有更快的算法来计算 (n! modulo m)。在每个乘法步骤都比减少更快。并且有没有比左右二元法更快的算法来计算 (a^p modulo m)。 这是我的代码:n!模数m ans=1 for(i
我有非常简单的代码循环遍历数组中的元素并检查是否index % 2 == 0。如果是这样,它应该改变颜色。 var e = document.getElementById("list").childN
让我简短一点。我正在计算 alert((Math.pow(7,35))%71) 但它给了我 61,而结果必须是 70。怎么了? 最佳答案 正如其他人之前提到的关于使用 Math.pow(7,35) 的
我试图弄清楚如何在汇编中计算模 10,所以我在 gcc 中编译了以下 c 代码,看看它想出了什么。 unsigned int i=999; unsigned int j=i%10; 令我惊讶的是我得到
例如使用以下输入: int num = -100 int divisor = 10 => -100 mod 10 = 0 (Edge-case: negative numbers as inpu
这个问题在这里已经有了答案: Random float number generation (14 个答案) 关闭 9 年前。 在 C++ 中,我希望得到一个随机 float 。据我所知,典型的随机
我试图找到潜在阶乘素数的除数(n!+-1 形式的数),因为我最近购买了 Skylake-X 工作站,我认为我可以使用 AVX512 指令提高一些速度。 算法简单,主要步骤是对同一个除数重复取模。主要是
我有一个保存角度(以度为单位)的变量,该角度可以是正值也可以是负值。我现在需要确保该数字仅在 0 到 360 之间。该数字是 double 。 执行此操作的好算法是什么?简单地执行角度 % 360 是
我有一个 UInt8 数组,我想计算 CheckSum8 模 256。如果字节总和小于 255,checkSum 函数返回正确的值。 例如 let bytes1 : [UInt8] = [1, 0xa
使用海湾合作委员会: printf("%i \n", -1 % (int)4); printf("%u \n", -1 % (unsigned int)4); 输出: -1 3 我可以跨平台依赖这种行
我无法理解代码中几行的含义。我最近开始学习 C++,并阅读了 Bjarne Stroustrup 的“编程:使用 C++ 的原理和实践”。第四章有个问题让我很困惑,所以我在网上搜索了一个解决方案以供引
我试图解决一个涉及大阶乘模质数的问题,并在另一个人的解决方案中发现了以下算法: long long factMod (long long n, long long p) { long long
我正在尝试计算 𝐹𝑛 模 𝑚,其中 𝑛 可能非常大:高达 10^18,𝐹𝑛 是第 n 个斐波那契数这是我的代码,它适用于小数字,但对于大数字,它会抛出 OutOfMemoryError 或
我有两个以 16 为模的循环整数,因此它们的值介于 0 和 15 之间。 我需要比较两个数字以确定 n_1 是否大于 n_0 n_1 > n_0 很明显,这个没有准确定义,所以我定义n_1如果小于前面
我一直在尝试使用 Java 处理一些更大的值,但遇到了一些我不理解的问题。出于某种原因,Java 似乎喜欢给我垃圾数据(尽管,我更可能告诉它给我垃圾数据) 这是一个片段,为清楚起见进行了编辑:
好吧,我今天做了一个小函数,它应该会生成一个随机字符串。 std::string randString(size_t length) { std::string randStr; fo
Ruby 的负数取模规则不明确。在 IRB 中: -7 % 3 == 2 应该是1!为什么? 最佳答案 因为 -7/3 在 Ruby 的整数除法语义下是 -3。 3*-3 是 -9,所以会留下 2
这个问题在这里已经有了答案: Calculating pow(a,b) mod n (14 个答案) 关闭 6 年前。 在 Javascript 中是否有获取大数模数的技巧。我用 modulo(7,
此代码使用公式 (a^x) % 101 检查值 a 是否唯一映射到值 1 到 100 local function f(a) found = {} bijective = true
在《Core Java Volume1》一书中有一条警告: CAUTION: The right-hand side argument of the shift operators is reduce
我是一名优秀的程序员,十分优秀!