我有Java GUI的问题.
我想创建三个JPanel大小不同的实例JFrame.JFrame尺寸300x800和Panel1安全工程师,Panel2大小为300x100和Panel3300X500.我想在下面添加这个面板.
如何解决这个问题呢?
我的refresh和refresh2方法导致出现一个新的窗口jpanel.我希望我的textareas在同一个窗口中更新.我不认为我正在调用正确的jpanel.我该如何解决?另外为什么要创建一个新窗口?
public static void main(String[] args) {
MPUComp frame = new MPUComp();
frame.setVisible(true);
}
public MPUComp() {
setTitle("Mpu Finder");
ImageIcon LoadIco = new ImageIcon(getClass().getResource("load.png"));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 799, 680);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
btnFind1.setBounds(250, 27, 68, 23);
contentPane.add(btnFind1);
btnLoadMpu.setBounds(328, 27, 36, 22);
btnLoadMpu.setIcon(LoadIco);
contentPane.add(btnLoadMpu);
btnFind2.setBounds(642, 27, 68, 23);
contentPane.add(btnFind2);
btnLoadMpu2.setBounds(720, 28, 36, 22);
btnLoadMpu2.setIcon(LoadIco);
contentPane.add(btnLoadMpu2);
menu();
}
public void refresh(String pane1) {
textArea_1.append(pane1 + "\n");
contentPane.revalidate();
contentPane.repaint();
setVisible(true);
}
public void refresh2(String pane1) …Run Code Online (Sandbox Code Playgroud) 这是事情......
我有2个GUI程序.
一个菜单程序,基本上是一个带有食物项按钮的框架,点击时按钮打开另一个程序,一个输入数量程序,一个带有文本字段的框架,数字按钮,取消和确认按钮.菜单程序将从输入数量程序访问用户确认的数量,以存储在矢量中,这样每次用户想要订购其他食品时,他只需点击另一个按钮并重复该过程.
现在我编写了大部分代码并且除了一件事之外一切都正常工作,输入数量程序返回的值有这个延迟的事情.
这就是我一步一步做的事情:
1)单击"菜单"中的食物项,打开"输入数量"窗口.
2)我输入了我想要的数字,它正确地显示在文本框中.
3)我按下确认哪个会做3件事,首先它将文本字段的值存储到变量中,第二个将调用dispose()方法,第三个是显示变量值的print语句(用于测试目的).
4)菜单程序然后检查用户是否已经按下Input程序中的Confirm按钮,如果为true,它将调用Input程序中名为getQuantity()的方法,该方法返回变量'quantity'的值并将其存储在矢量.
5)之后执行另一个print语句以检查传递的值是否正确,然后调用方法print()以显示已订购的项目名称及其记录的数量.
以下是GUI的屏幕截图,代码将在其下方.


输入数量程序中CONFIRM BUTTON的ActionPerformed方法:
private void ConfirmButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
confirmed = true;
q= textField.getText().toString();
quantity =Integer.parseInt(q) ;
System.out.println("getQTY method inside Input Quantity Interface:" +getQuantity());
System.out.println("Quantity from confirmButton in Input Quantity Interface actionPerformed: "+quantity);
//getQuantity();
}
Run Code Online (Sandbox Code Playgroud)
菜单程序中菜单项按钮的动作监听类别执行上述步骤2:
class f implements ActionListener {
@Override
public void actionPerformed(ActionEvent e)
{
inputGUI.setVisible(true);
int q =0;
q=inputGUI.getQuantity(); //call method to get value from Input Program
System.out.println("Quantity inside Menu actionperformed …Run Code Online (Sandbox Code Playgroud) 我正在尝试用C#学习GUI编程,我对C#中TextBox的默认代码有以下问题:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication34
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
// Textbox programming goes here
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我想尝试与TexBox编程有点不同的东西时,类似于这段代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication20
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private …Run Code Online (Sandbox Code Playgroud) 所以这是我这个项目的第3个帖子,希望是最后一个.因此,当我的程序在其他类中进行数学运算时,它需要出现在JLabel中.问题是,它没有显示出来.Maby你们其中一个可以帮帮我吗?对不起,当我发布它时代码将会被删除,我无法解决它.
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class AFA {
public void answer() {
System.out.println("1");
int area = (int) (AF.length * AF.width);
String an = String.valueOf(area);
JFrame answer = new JFrame();
answer.setBackground(Color.yellow);
JPanel pan2 = new JPanel();
JLabel a = new JLabel("The answer is " + an + "We got this by multiplying the Lenght by the width");
pan2.add(a);
System.out.println("1");
answer.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud) 我想在Android应用程序中使用新的自定义字体.请在解释时准确而具体,我是新手.也就是说,我想让我的Android应用程序使用这些新的Android自定义字体http://developer.android.com/design/style/typography.html.谢谢.请帮忙.
我有一个类在底部实现了smithWaterman算法,我决定将main放在GUI中并将其打印出矩阵.我一直得到NullPointerException.我不知道如何解决它,有没有人看到错误?谢谢.
package main;
import java.util.*;
import java.util.*;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.List;
import java.lang.Math;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.ListModel;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import java.lang.Math;
/**
* Smith-Waterman Algorithm:
*
* @author Jomana Sherif Final Project SE 165 Fall2012
*/
public class smithWaterman2 {
// Initializing the two array lists of the input
StringBuffer store1 = new StringBuffer(0); …Run Code Online (Sandbox Code Playgroud) 如何在android中使用2个不同风格的标签做1个按钮?(就像图片一样)谢谢
我需要在我的Java GUI中运行后台线程,该线程仅在我单击按钮时运行,并在我再次单击该按钮时暂停.我不确定如何设置它,但我已经在我的构造函数中放置了一个线程,并且当我将特定布尔值设置为TRUE时,while循环设置为通过.一个按钮从设置此布尔值TRUE或FALSE切换.
我在这个GUI中的其他所有工作都很好.当我尝试调试线程时,它实际上是在我逐步完成线程时工作但当我尝试完全运行GUI时没有任何内容.GUI相当大,所以我要设置一部分构造函数和按钮的动作监听器.其余的代码是不必要的,因为它工作得很好.我需要知道我在做错了什么:
public BasketballGUI() {
// certain labels and buttons
Thread runningSim = new Thread() {
public void run() {
while(simRun) {
// do stuff here
}
}
};
runningSim.start();
}
// other GUI stuff
// actionListener that should run the thread.
class SimButtonListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
if(!simRun) {
simRun = true;
sim.setText("Pause Simulator");
}
else if(simRun) {
simRun = false;
sim.setText("Run Simulator");
}
// other stuff in this actionListener
}
}
Run Code Online (Sandbox Code Playgroud) 在这个程序中,我需要我的程序将类的状态放入一个不可编辑的JTextArea中,但是我一直得到一个NullPointerException.我有一种感觉,这与每次启动时对象被反序列化的事实有关.如果我删除它并用实际的String替换它,它工作正常.我该怎么办?我将在下面发布两个课程.
BankGUI类:
package GUIs;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagLayout;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.UIManager;
public class BankGUI {
BankAccount account;
private void deserializeAccount() {
try {
ObjectInputStream objectStream2 = new ObjectInputStream(
new FileInputStream("bankAccounts.txt"));
account = (BankAccount) objectStream2.readObject();
objectStream2.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] …Run Code Online (Sandbox Code Playgroud)