我正在尝试打印这个:
jbFirstActionPerformed
jbFirstActionPerformed
jbTwoActionPerformed
jbTwoActionPerformed
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: javax.swing.JPanel[,0,0,0x0,invalid,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.synth.SynthBorder@fa9981,flags=9,maximumSize=,minimumSize=,preferredSize=] 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.minimumLayoutSize(GroupLayout.java:896)
at java.awt.Container.minimumSize(Container.java:1846)
at java.awt.Container.getMinimumSize(Container.java:1830)
at javax.swing.JComponent.getMinimumSize(JComponent.java:1746)
at javax.swing.GroupLayout$ComponentSpring.calculateNonlinkedMinimumSize(GroupLayout.java:3008)
at javax.swing.GroupLayout$ComponentSpring.calculateMinimumSize(GroupLayout.java:2972)
at javax.swing.GroupLayout$Spring.getMinimumSize(GroupLayout.java:1336)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1636)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1627)
at javax.swing.GroupLayout$Group.calculateMinimumSize(GroupLayout.java:1598)
at javax.swing.GroupLayout$Spring.getMinimumSize(GroupLayout.java:1336)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1636)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1622)
at javax.swing.GroupLayout$Group.calculateMinimumSize(GroupLayout.java:1598)
at javax.swing.GroupLayout$ParallelGroup.calculateMinimumSize(GroupLayout.java:2569)
at javax.swing.GroupLayout$Spring.getMinimumSize(GroupLayout.java:1336)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1636)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1622)
at javax.swing.GroupLayout$Group.calculateMinimumSize(GroupLayout.java:1598)
at javax.swing.GroupLayout$Spring.getMinimumSize(GroupLayout.java:1336)
at javax.swing.GroupLayout.calculateAutopadding(GroupLayout.java:1068)
at javax.swing.GroupLayout.prepare(GroupLayout.java:1058)
at javax.swing.GroupLayout.minimumLayoutSize(GroupLayout.java:896)
at java.awt.Container.minimumSize(Container.java:1846)
at java.awt.Container.getMinimumSize(Container.java:1830)
at javax.swing.JComponent.getMinimumSize(JComponent.java:1746)
at javax.swing.plaf.basic.BasicTabbedPaneUI$TabbedPaneLayout.calculateSize(BasicTabbedPaneUI.java:2303)
at javax.swing.plaf.basic.BasicTabbedPaneUI$TabbedPaneLayout.minimumLayoutSize(BasicTabbedPaneUI.java:2282jbTwoActionPerformed
)
at java.awt.Container.minimumSize(Container.java:1846)
jbTwoActionPerformed
at java.awt.Container.getMinimumSize(Container.java:1830)
at javax.swing.JComponent.getMinimumSize(JComponent.java:1746)
jbTwoActionPerformed
at javax.swing.GroupLayout$ComponentSpring.calculateNonlinkedMinimumSize(GroupLayout.java:3008)
at javax.swing.GroupLayout$ComponentSpring.calculateMinimumSize(GroupLayout.java:2972)
at javax.swing.GroupLayout$Spring.getMinimumSize(GroupLayout.java:1336)
at javax.swing.GroupLayout$ComponentSpring.calculatePreferredSize(GroupLayout.java:2979)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1346)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1638)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1622)
at javax.swing.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1602)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1346)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1638)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1622)
at javax.swing.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1602)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1346)
at javax.swing.GroupLayout$SequentialGroup.setValidSize(GroupLayout.java:2017)
at javax.swing.GroupLayout$Group.setSize(GroupLayout.java:1587jbTwoActionPerformed
)
at javax.swing.GroupLayout.calculateAutopadding(GroupLayout.java:1079)
at javax.swing.GroupLayout.layoutContainer(GroupLayout.java:918)
at java.awt.Container.layout(Container.java:1508)
at java.awt.Container.doLayout(Container.java:1497)
at java.awt.Container.validateTree(Container.java:1693jbTwoActionPerformed
)
at java.awt.Container.validateTree(Container.java:1702)
at java.awt.Container.validateTree(Container.java:1702)
at java.awt.Container.validateTree(Container.java:1702)
at java.awt.Container.validate(Container.java:1628)
at java.awt.Window.dispatchEventImpl(Window.java:2748)
at java.awt.Component.dispatchEvent(Component.java:4703)
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$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
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)
jbTwoActionPerformed
用户输入他们每天在同一行上工作的小时数,这样就可以计算出工作小时数,但我甚至不确定这是否可行。这是我当前代码的片段:
Sun Mon Tue Wed Thur Fri Sat
4 3 8 5 4 4 8
我目前的输出:
System.out.println("\t"+"\t"+"\t"+"\t"+"\t" + "Sun" + "\t" + "Mon" + "\t" + "Tue" + "\t" + "Wed" + "\t" + "Thur" + "\t" + "Fri" + "\t" + "Sat");
for (int j = 0; j < hoursWorkedPerDay.length; j++) {
System.out.print("Enter hours worked for Employee " + (j+1) + ":"+ "\t" + " " + " ");
for (int k = 0; k < hoursWorkedPerDay[0].length; k++) {
hoursWorkedPerDay[j][k] = scan.nextInt();
}
} // End of for loop
我的问题是,这是可能的还是我必须垂直打印?谢谢!
答案 0 :(得分:1)
您必须在获取值之前打印工作日。像这样:
cabal install gd
答案 1 :(得分:1)
如果我理解你的问题,那么我如何在一行上打印一组数字&#39;?如果是这样,主要有两种方式:
对每个号码使用print
(之间带有制表符),然后使用println
结束该行。
将所有数字加入一个字符串,然后使用println
输出整个字符串。
这是一个简单的Java 8习惯用法,它通过将它们连接到带有制表符分隔符的字符串,在单个语句中打印所有小时:
IntStream.range(0, employeeCount)
.mapToObj(emp -> Arrays.stream(hoursWorked[emp]).collect(Collectors.joining("\t")))
.forEach(System.out::println);