我是java的初学者.我JPanel在java(NetBeans)中创建了一个表单.然后,我定义了一些动作,如数学计算.当我运行我的项目时,我没有收到任何错误,但我JPanel在运行时看不到表单.因为我没有在主类中定义jform.如何JPanel在主类中定义表单JPanel以在运行时向我显示表单.
public class NewJPanel extends javax.swing.JPanel {
public NewJPanel() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jLabel1.setText("First Number:");
jLabel2.setText("Second Number:");
jLabel3.setText("Result:");
jButton1.setText("Add"); …Run Code Online (Sandbox Code Playgroud) 我在书中看到了下面的代码.我知道void方法不能返回值.当我运行代码时,编译器无法打印修改后的数组,而在本书中,会显示值.如何修复代码以打印修改后的数组?
public static void main(String[] args) {
int[] array = {1, 2, 3, 4, 5};
System.out.println("The values of original array are:");
for(int value: array)
{
System.out.print(value + "\t");
}
modifyArray(array);
System.out.println("The values after modified array are:");
for (int value:array)
{
System.out.print(value + "\t");
}
}
public static void modifyArray(int[] b)
{
for (int counter=0; counter<=b.length; counter++)
{
b[counter] *=2;
}
}
Run Code Online (Sandbox Code Playgroud)