📄 appframe.java
字号:
jPanel1.add(jLabel7, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(18, 6, 13, 0), 3, 3));
jPanel1.add(jTextField7, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(18, 11, 13, 30), 13, -2));
settingPanel.add(jPanel2, null);
jPanel2.add(jLabel2, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(7, 12, 0, 0), 1, -3));
jPanel2.add(jTextField2, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(7, 13, 10, 26), 1, -2));
jPanel2.add(jLabel4, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(23, 12, 0, 8), -1, -5));
jPanel2.add(jTextField4, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(22, 13, 9, 26), 1, -2));
jPanel2.add(jLabel6, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(22, 12, 11, 11), 8, 4));
jPanel2.add(jTextField6, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(22, 13, 11, 26), 1, -2));
settingPanel.add(jPanel3, null);
jToolBar.add( jButton1 );
jToolBar.add( jButton2 );
jToolBar.add( jButton3 );
contentPane.add( observerPanel, BorderLayout.SOUTH );
contentPane.add( jToolBar, BorderLayout.NORTH );
observerPanel.add( selectPanel, BorderLayout.WEST );
selectPanel.add( groupInitButton, null );
selectPanel.add( groupResultButton, null );
selectPanel.add( routineButton, null );
selectPanel.add( cqResultTransButton, null );
observerPanel.add( parentPanel, BorderLayout.CENTER );
//my inits
this.buttonGroup1.add( this.setRandomPositionButton );
this.buttonGroup1.add( this.setFixPositionButton );
this.buttonGroup2.add( this.groupInitButton );
this.buttonGroup2.add( this.routineButton );
this.buttonGroup2.add( this.cqResultTransButton );
this.buttonGroup2.add( this.groupResultButton );
//添加各种演示面板-----------------------------------------
parentPanel.add( settingPanel, "settingPanel" );
parentPanel.add(groupResultPanel,"groupResultPanel");
parentPanel.add(routineResultPanel,"routineResultPanel");
parentPanel.add(cqResultTransPanel,"cqResultTransPanel");
//-------------------------------------------------------
groupResultPanel.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(groupTable, null);
//添加事件---------------------------------------------------------------
this.groupInitButton.addItemListener( new ItemListener() {
public void itemStateChanged( ItemEvent event ) {
if( groupInitButton.isSelected() ) {
cardLayout1.show(parentPanel,"settingPanel");
setDisShowing();
}
}
} );
this.groupResultButton.addItemListener( new ItemListener() {
public void itemStateChanged( ItemEvent event ) {
if( groupResultButton.isSelected() ) {
cardLayout1.show(parentPanel,"groupResultPanel");
setDisShowing();
groupResultPanel.isShowing = true;
}
}
} );
this.routineButton.addItemListener(new ItemListener() {
public void itemStateChanged( ItemEvent event ) {
if( routineButton.isSelected() ) {
cardLayout1.show(parentPanel,"routineResultPanel");
setDisShowing();
routineResultPanel.isShowing = true;
}
}
} );
this.cqResultTransButton.addItemListener(new ItemListener() {
public void itemStateChanged( ItemEvent event ) {
if( cqResultTransButton.isSelected() ) {
cardLayout1.show(parentPanel,"cqResultTransPanel");
setDisShowing();
cqResultTransPanel.isShowing = true;
}
}
} );
//----------------------------------------------------------------------
this.groupResultPanel.groupPanelInit(this,this.groupTable);
this.routineResultPanel.routineResultPanelInit(this);
}
//setDisShowing
private void setDisShowing()
{
this.groupResultPanel.isShowing = false;
this.routineResultPanel.isShowing=false;
this.cqResultTransPanel.isShowing=false;
}
//File | Exit action performed
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
//Help | About action performed
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
AppFrame_AboutBox dlg = new AppFrame_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.pack();
dlg.show();
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public void itemStateChanged(ItemEvent e) {}
//--------------------------------------------------------------------------
void clearButton_actionPerformed(ActionEvent e) {
this.jTextField1.setText(""); this.jTextField2.setText("");
this.jTextField3.setText(""); this.jTextField4.setText("");
this.jTextField6.setText(""); this.jTextField7.setText("");
}
//整个程序开始执行
void startButton_actionPerformed(ActionEvent e) {
if(demoManger != null)
{
if(demoManger.currentThread.isAlive())
demoManger.currentThread.stop();
this.remove(demoManger.demoPanel);
demoManger = null;
}
if( !checkValidation())
return;
demoManger = new DemoManger( this );
updateDefaultSettings();
this.startButton.setEnabled(false);
this.resetButton.setEnabled(true);
}
private void updateDefaultSettings()
{
if(this.setRandomPositionButton.isSelected()){
demoManger.setRandom( true );
demoManger.setRandomPosition();
}
StringBuffer sb = new StringBuffer();
sb.append("range:"+this.jTextField1.getText().trim()+"@");
sb.append("validRange:"+this.jTextField2.getText().trim()+"@");
sb.append("helloBroadcastTime:"+this.jTextField3.getText().trim()+"@");
sb.append("updatePositionTime:"+this.jTextField4.getText().trim()+"@");
sb.append("delayTime:"+this.jTextField7.getText().trim()+"@");
sb.append("rmTime:"+this.jTextField6.getText().trim()+"@");
demoManger.updateDefaultSetting(sb.toString());
demoManger.start();
validate();
}
//审查输入值的有效性
private boolean checkValidation()
{
if( !this.jTextField1.getText().trim().equals("") &&
!this.jTextField2.getText().trim().equals(""))
{
if( Integer.parseInt(this.jTextField1.getText().trim()) <=
Integer.parseInt(this.jTextField2.getText().trim()))
{
JOptionPane.showMessageDialog(this,"ValidRange can't larger than range!","Error",0);
return false;
}
}
if( !this.jTextField3.getText().trim().equals("") )
if( Integer.parseInt(this.jTextField3.getText().trim())<=0)
{showInputNumberError(); return false;}
if(!this.jTextField4.getText().trim().equals(""))
if( Integer.parseInt(this.jTextField4.getText().trim())<=0)
{showInputNumberError(); return false;}
if(!this.jTextField6.getText().trim().equals("") )
if( Integer.parseInt(this.jTextField6.getText().trim())<=0)
{showInputNumberError(); return false;}
if(!this.jTextField7.getText().trim().equals("") )
if( Integer.parseInt(this.jTextField7.getText().trim())<=0)
{showInputNumberError(); return false;}
return true;
}
void showInputNumberError(){
JOptionPane.showMessageDialog(this,"Time must be positive number!","Error",0);
}
void jButton3_actionPerformed(ActionEvent e) {
jMenuHelpAbout_actionPerformed(e);
}
//reset所有的值--还有待加强
void resetButton_actionPerformed(ActionEvent e) {
this.resetButton.setEnabled(false);
this.startButton.setEnabled(true);
if(demoManger != null)
{
if(demoManger.currentThread.isAlive())
demoManger.currentThread.stop();
this.remove(demoManger.demoPanel);
demoManger = null;
}
if( !checkValidation())
return;
demoManger = new DemoManger( this );
updateDefaultSettings();
}
//--------------------------------------------------------------------------
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -