摇摆:GUI犯规显示我的组件

我相信这只是一个小错误,但我不能找到它。 当我开始我的服务器GUI在它的组件犯规出现。 我的一切是正确的大小空白页。

import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; public class ServerGUI extends javax.swing.JFrame { private ServerSocket server; private int port; private int numberOfObject; private int counter = 1; private ObjectClass[] Object; private Server bss; public static volatile int[] Allocation; public void setServerGUI(Server bss, int port, int numberOfObject, ObjectClass[] Object) { this.bss = bss; this.port = port; this.numberOfObject = numberOfObject; this.Object = Object; } public ServerGUI() { try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(ServerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(ServerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(ServerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(ServerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* * Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { setVisible(true); } }); initComponents(); } public void startServing() { System.out.println("STARTSERVING"); try { server = new ServerSocket(port); } catch (IOException e1) { System.out.println("IOException in startServing()"); } while (true) { Socket ADClient = null; int free=0; try { ADClient = server.accept(); for (int j = 0; j < numberOfObject; j++) { if ((Allocation[j] == -1)) { free = j; Allocation[free] = counter; } } System.out.println("" + Object[free].getNumber()); new ServerThread(ADClient, counter++, Object[free]).start(); } catch (IOException e) { System.out.println("IOException: server.accept() schlug fehl."); } } } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { scrollPaneState1 = new javax.swing.JScrollPane(); textAreaState1 = new javax.swing.JTextArea(); scrollPaneServer1 = new javax.swing.JScrollPane(); textAreaServer1 = new javax.swing.JTextArea(); scrollPaneState2 = new javax.swing.JScrollPane(); textAreaState2 = new javax.swing.JTextArea(); scrollPaneServer2 = new javax.swing.JScrollPane(); textAreaServer2 = new javax.swing.JTextArea(); scrollPaneState3 = new javax.swing.JScrollPane(); textAreaState3 = new javax.swing.JTextArea(); scrollPaneServer3 = new javax.swing.JScrollPane(); textAreaServer3 = new javax.swing.JTextArea(); scrollPaneMain = new javax.swing.JScrollPane(); textAreaMain = new javax.swing.JTextArea(); labelNr1 = new javax.swing.JLabel(); labelNr2 = new javax.swing.JLabel(); labelNr3 = new javax.swing.JLabel(); labelStateResponse1 = new javax.swing.JLabel(); labelStateResponse2 = new javax.swing.JLabel(); labelStateResponse3 = new javax.swing.JLabel(); labelServerResponse1 = new javax.swing.JLabel(); labelServerResponse2 = new javax.swing.JLabel(); labelServerResponse3 = new javax.swing.JLabel(); labelMainResponse = new javax.swing.JLabel(); beendenButton = new javax.swing.JButton(); backButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Server - Running"); scrollPaneState1.setEnabled(false); textAreaState1.setColumns(20); textAreaState1.setRows(5); scrollPaneState1.setViewportView(textAreaState1); scrollPaneServer1.setEnabled(false); textAreaServer1.setColumns(20); textAreaServer1.setRows(5); scrollPaneServer1.setViewportView(textAreaServer1); scrollPaneState2.setEnabled(false); textAreaState2.setColumns(20); textAreaState2.setRows(5); scrollPaneState2.setViewportView(textAreaState2); scrollPaneServer2.setEnabled(false); textAreaServer2.setColumns(20); textAreaServer2.setRows(5); scrollPaneServer2.setViewportView(textAreaServer2); scrollPaneState3.setEnabled(false); textAreaState3.setColumns(20); textAreaState3.setRows(5); scrollPaneState3.setViewportView(textAreaState3); scrollPaneServer3.setEnabled(false); textAreaServer3.setColumns(20); textAreaServer3.setRows(5); scrollPaneServer3.setViewportView(textAreaServer3); scrollPaneMain.setEnabled(false); textAreaMain.setColumns(20); textAreaMain.setRows(5); scrollPaneMain.setViewportView(textAreaMain); labelNr1.setText("Nr: "); labelNr1.setDoubleBuffered(true); labelNr2.setText("Nr: "); labelNr3.setText("Nr: "); labelStateResponse1.setText("State Respone:"); labelStateResponse2.setText("State Response:"); labelStateResponse3.setText("State Response:"); labelServerResponse1.setText("Server Resonse:"); labelServerResponse2.setText("Server Response:"); labelServerResponse3.setText("Server Response:"); labelMainResponse.setText("Main Response:"); beendenButton.setText("beenden"); beendenButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { beendenButtonActionPerformed(evt); } }); backButton.setText("zurück"); backButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { backButtonActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(labelNr1) .addComponent(labelStateResponse1)) .addGap(199, 199, 199) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scrollPaneState2, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(labelServerResponse2) .addComponent(labelStateResponse2) .addComponent(labelNr2)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scrollPaneState3) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(labelServerResponse3) .addComponent(labelStateResponse3) .addComponent(labelNr3)) .addGap(0, 0, Short.MAX_VALUE)))) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(scrollPaneServer1) .addComponent(scrollPaneState1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(scrollPaneServer2, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(scrollPaneServer3)) .addGroup(layout.createSequentialGroup() .addComponent(labelServerResponse1) .addGap(738, 738, 738)) .addComponent(scrollPaneMain))) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(labelMainResponse)) .addGroup(layout.createSequentialGroup() .addGap(326, 326, 326) .addComponent(backButton) .addGap(18, 18, 18) .addComponent(beendenButton))) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(labelNr1) .addComponent(labelNr2) .addComponent(labelNr3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(labelStateResponse1) .addComponent(labelStateResponse2) .addComponent(labelStateResponse3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(scrollPaneState2, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(scrollPaneState1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(scrollPaneState3, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(labelServerResponse1) .addComponent(labelServerResponse2) .addComponent(labelServerResponse3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scrollPaneServer2, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(scrollPaneServer1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(scrollPaneServer3, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(labelMainResponse) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(scrollPaneMain, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(beendenButton) .addComponent(backButton)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void beendenButtonActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0); } private void backButtonActionPerformed(java.awt.event.ActionEvent evt) { bss.setVisible(true); this.dispose(); } // Variables declaration - do not modify private javax.swing.JButton backButton; private javax.swing.JButton beendenButton; private javax.swing.JLabel labelNr1; private javax.swing.JLabel labelNr2; private javax.swing.JLabel labelNr3; private javax.swing.JLabel labelMainResponse; private javax.swing.JLabel labelServerResponse1; private javax.swing.JLabel labelServerResponse2; private javax.swing.JLabel labelServerResponse3; private javax.swing.JLabel labelStateResponse1; private javax.swing.JLabel labelStateResponse2; private javax.swing.JLabel labelStateResponse3; private javax.swing.JScrollPane scrollPaneMain; private javax.swing.JScrollPane scrollPaneServer1; private javax.swing.JScrollPane scrollPaneServer2; private javax.swing.JScrollPane scrollPaneServer3; private javax.swing.JScrollPane scrollPaneState1; private javax.swing.JScrollPane scrollPaneState2; private javax.swing.JScrollPane scrollPaneState3; private javax.swing.JTextArea textAreaMain; private javax.swing.JTextArea textAreaServer1; private javax.swing.JTextArea textAreaServer2; private javax.swing.JTextArea textAreaServer3; private javax.swing.JTextArea textAreaState1; private javax.swing.JTextArea textAreaState2; private javax.swing.JTextArea textAreaState3; // End of variables declaration }

这个类被调用在这里:

ServerGUI bssGUI = new ServerGUI(); bssGUI.setServerGUI(this, 4242, object.length,object); bssGUI.setVisible(true); bssGUI.startServing();

--------------解决方案-------------

正如我可以看到这个代码与NetBeans产生..重新设计网页,因为它是阻力的问题拖放和复制功能:在适当的地方 - 只有业务功能..小心其中u是把业务功能becse如果u把它放错了地方,然后ü可能再次结束了这个相同的问题。 例如..如果u正在为听众写代码然后根据下面给出

backButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
backButtonActionPerformed(evt);
}
});

是正确的 。 这里要注意的好东西,就是你包裹我们的代码的方法,并调用该方法从其中u正打算从调用它的地方。

和u,可答案贴Ÿ吉米被照顾FUL。 我觉得这将是浪费时间去通过这个代码,并找出probblem。 其拖放的问题。

也请记住,没有成品的配件应该重叠,并且应该有已被删除,但他们的记忆尚未公布任何额外的组件。

这是很多的代码,您使用NetBeans :)我能发现的唯一的事情是,你应该叫缺点之一initComponents();你打电话之前setVisible(true);

此外,请确保您没有赶上你的任何异常阅读您正在创建日志文件(或加printlines)

看来你在一个线程执行初始化,但调用setVisible另一个线程方法(裹着invokeLater的构造函数)。 它通常是不好的做法调用UI的东西比从事件调度线程其他线程,更不用说导致竞争条件的。 尝试删除invokeLater从构造函数和包装initalization来代替:

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
ServerGUI bssGUI = new ServerGUI();
bssGUI.setServerGUI(this, 4242, object.length,object);
bssGUI.setVisible(true);
bssGUI.startServing();
}
};

分类:java的 时间:2015-03-15 人气:1
本文关键词: 用户界面,JAVA,秋千
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.248 (s). 10 q(s)