Я продолжаю получать ошибки при попытке запустить мою программу, хотя при создании программы в сетевых компонентах у меня нет ошибок. Только когда я пытаюсь скомпилировать, всплывают 50 ошибок. Кто-то объяснил, что мой JTextField
не был привязан к горизонтальной группе, и я подумал, что исправил это, но, похоже, нет.
public class TrianglePerimeter extends javax.swing.JFrame {
public TrianglePerimeter() {
utilizeComponents();
}
@SuppressWarnings("Not Checked")
private void utilizeComponents() {
sideOneInput = new javax.swing.JTextField();
sideTwoInput = new javax.swing.JTextField();
sideThreeInput = new javax.swing.JTextField();
sideOneLabel = new javax.swing.JLabel();
sideTwoLabel = new javax.swing.JLabel();
sideThreeLabel = new javax.swing.JLabel();
findPerimeterButton = new javax.swing.JButton();
perimeterLabel = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Perimeter of a Triangle");
findPerimeterButton.setText("Find the Perimeter");
findPerimeterButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
findPerimeterButtonActionPerformed(evt);
}
}
);
sideOneLabel.setText("Side One");
sideTwoLabel.setText("Side Two");
sideThreeLabel.setText("Side Three");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(findPerimeterButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(sideOneInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sideTwoInput)
.addComponent(sideThreeInput)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(16, 16, 16)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(sideOneLabel, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(sideTwoLabel, javax.swing.GroupLayout.Alignment.TRAILING)))
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(sideThreeLabel)))
.addGap(56, 56, 56)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(perimeterLabel)))))
.addContainerGap(67, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(sideOneInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sideOneLabel))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(sideTwoInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sideTwoLabel))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(sideThreeInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sideThreeLabel))
.addGap(18, 18, 18)
.addComponent(findPerimeterButton)
.addContainerGap(27, Short.MAX_VALUE)
));
pack();
}
private void findPerimeterButtonActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println(evt);
try {
double tempPerimeter = (Double.parseDouble(sideOneInput.getText())) + (Double.parseDouble(sideTwoInput.getText())) + (Double.parseDouble(sideThreeInput.getText()));
perimeterLabel.setText(tempPerimeter + " is the perimeter");
} catch (NumberFormatException e) {
System.err.println("NumberFormatException: " + e.getMessage());
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(() -> {
new TrianglePerimeter().setVisible(true);
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel sideOneLabel;
private javax.swing.JLabel sideTwoLabel;
private javax.swing.JLabel sideThreeLabel;
private javax.swing.JButton findPerimeterButton;
private javax.swing.JLabel perimeterLabel;
private javax.swing.JTextField sideOneInput;
private javax.swing.JTextField sideTwoInput;
private javax.swing.JTextField sideThreeInput;
private javax.swing.JTextField tempTextField;
// End of variables declaration//GEN-END:variables
}
Это ошибки
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: javax.swing.JTextField[,0,0,0x0,invalid,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@3566d06c,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=0,columnWidth=0,command=,horizontalAlignment=LEADING] is not attached to a horizontal group
at javax.swing.GroupLayout.checkComponents(GroupLayout.java:1086)
at javax.swing.GroupLayout.prepare(GroupLayout.java:1040)
at javax.swing.GroupLayout.preferredLayoutSize(GroupLayout.java:878)
at java.awt.Container.preferredSize(Container.java:1799)
at java.awt.Container.getPreferredSize(Container.java:1783)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1664)
at javax.swing.JRootPane$RootLayout.preferredLayoutSize(JRootPane.java:920)
at java.awt.Container.preferredSize(Container.java:1799)
at java.awt.Container.getPreferredSize(Container.java:1783)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1664)
at java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:719)
at java.awt.Container.preferredSize(Container.java:1799)
at java.awt.Container.getPreferredSize(Container.java:1783)
at java.awt.Window.pack(Window.java:809)
at TrianglePerimeter.TrianglePerimeter.utilizeComponents(TrianglePerimeter.java:96)
at TrianglePerimeter.TrianglePerimeter.<init>(TrianglePerimeter.java:16)
at TrianglePerimeter.TrianglePerimeter.lambda$main$0(TrianglePerimeter.java:111)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Может кто-нибудь сказать мне, где я иду не так?