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

📄 component.java

📁 Java门电路画图器 基本功能: 1。文件的保存
💻 JAVA
字号:
package ding;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 * <p>Title: 门电路画图器</p>
 * <p>Description: www.1shu.net</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: EyeSome</p>
 * @author ES
 * @version 1.0
 */

public class component
    extends JFrame
    implements ActionListener {
  mainFrame mFrame;
  ImageIcon icon[];
  JButton[] buttons;
  Font tmpF = new Font("Dialog", Font.PLAIN, 12);

  int i;
  String mess;
  public component() {
    super();
  }

  public component(mainFrame frame) {
    super("请选择元件");
    setSize(715, 505);
    mFrame = frame;

    GridLayout gr = new GridLayout( (int) (mFrame.yjtNo / 2), 4);
    //System.out.println(Math.sqrt(mFrame.yjtNo)+" --- ");
    //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel pane = new JPanel();
    pane.setLayout(gr);
    JScrollPane scroll = new JScrollPane(pane,
                                         JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                                         JScrollPane.
                                         HORIZONTAL_SCROLLBAR_AS_NEEDED);
    icon = new ImageIcon[mFrame.yjtNo];
    buttons = new JButton[mFrame.yjtNo];
    //System.out.println("picPath:"+mFrame.yjt[0].picPath+"yjtNo:"+mFrame.yjtNo);
    for (i = 0; i < mFrame.yjtNo; i++) {
      icon[i] = new ImageIcon(mFrame.yjt[i].picPath);
      //System.out.println("picPath:" + mFrame.yjt[i].picPath);
      buttons[i] = new JButton(frame.yjt[i].des,icon[i]);
      buttons[i].setFont(tmpF);
      mess = "按钮 " + String.valueOf(i) + "被点击";
      buttons[i].addActionListener(
          new ActionListener() {
        String m2;
        int j;
        //yuanjian yjtmp;
        public void actionPerformed(ActionEvent e) {
          Object src = e.getSource();
          for (j = 0; j < mFrame.yjtNo; j++) {
            if (src == buttons[j]) {
              //yjtmp = mFrame.yjt[j].getValue();
              mFrame.yjc[mFrame.yjcNo] = mFrame.yjt[j].getValue();
              mFrame.yjcNo++;
              /*元件统计加一*/
              mFrame.yjt[j].number++;
              //System.out.println(mFrame.yjt[j].des+" :"+mFrame.yjt[j].number);
              //m2 = "按钮 "+String.valueOf(j)+"被点击";
              break;
            }
          }
          //System.out.println(src);
          //JOptionPane.showMessageDialog(null,m2);
          dispose(); // 关闭窗口
        }
      }
      );
      pane.add(buttons[i]);
    }
    setContentPane(scroll);
    //show();
  }

  public void actionPerformed(ActionEvent evt) {

  }
}

⌨️ 快捷键说明

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