⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clickpanel.java

📁 这个是一个关于JMX的一个源代码
💻 JAVA
字号:
package dwjmxservice.basic;import java.awt.*;import java.awt.event.*;import javax.swing.*;class ClickPanelModel {   int val = 0;   ClickPanel myView;   public ClickPanelModel(ClickPanel inView) {     myView = inView;     }   public void setVal(int inVal) {     val = inVal;     myView.notifyUpdate();     }   public void incVal() {    val = ++val;    myView.notifyUpdate();   }   public void decVal() {    val = --val;    myView.notifyUpdate();   }   public int getVal () {     return val;  }}class ClickPanelController {  private ClickPanel myPanel;  public ClickPanelModel myModel;  public ClickPanelController( ClickPanelModel inModel, ClickPanel inPanel) {    myPanel = inPanel;    myModel = inModel;  }  public void onIncButtonClicked() {     myModel.incVal();  }  public void onDecButtonClicked() {     myModel.decVal();  }}public class ClickPanel extends JPanel {  ClickPanelModel myModel = null;  ClickPanelController myController = null;  JLabel dispLabel = new JLabel();  JPanel buttonsPanel = new JPanel();  JButton incButton = new JButton();  JButton decButton = new JButton();  BorderLayout borderLayout = new BorderLayout();  GridLayout gridLayout = new GridLayout();  public ClickPanel() {//      enableEvents(AWTEvent.WINDOW_EVENT_MASK);    try {      guiInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  public void initController() {   myModel = new ClickPanelModel(this);    myController = new ClickPanelController(myModel, this);  }   private void guiInit() throws Exception  {    this.setLayout(borderLayout);    this.setPreferredSize(new Dimension(100, 200));    dispLabel.setBackground(Color.white);    dispLabel.setFont(new java.awt.Font("Serif", 1, 89));    dispLabel.setMaximumSize(new Dimension(500, 400));    dispLabel.setOpaque(true);    dispLabel.setToolTipText("Current Reading");    dispLabel.setHorizontalAlignment(SwingConstants.CENTER);    dispLabel.setText("0");    buttonsPanel.setPreferredSize(new Dimension(50, 50));    incButton.setFont(new java.awt.Font("SansSerif", 1, 22));    incButton.setText("+");    incButton.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        incButtonClicked(e);      }    });    decButton.setFont(new java.awt.Font("SansSerif", 1, 22));    decButton.setText("-");    decButton.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        decButtonClicked(e);      }    });     gridLayout.setColumns(1);   gridLayout.setRows(2);    gridLayout.setVgap(1);    buttonsPanel.setLayout(gridLayout);    this.add(dispLabel,  BorderLayout.CENTER);    this.add(buttonsPanel, BorderLayout.EAST);    buttonsPanel.add(incButton, null);    buttonsPanel.add(decButton, null);  } void incButtonClicked(ActionEvent e) {   myController.onIncButtonClicked();  } void decButtonClicked(ActionEvent e) {   myController.onDecButtonClicked(); }public void notifyUpdate() {   dispLabel.setText("" + myModel.getVal());}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -