/** * Adds the componentType buttons to the Panel of Main Window. * * @param pkg_name whose componentType buttons will be added * @param a needed for the addition of the ActionListener of respective buttons and calling method * of Pad_Draw */ public void add_componentType_buttons(package_cls pkg_name, final counts a) { int i; JLabel pkg_hdng = new JLabel(pkg_name.getName()); panel.add(pkg_hdng); for (i = 0; i < pkg_name.getComponentType_list().size(); i++) { final componentType cmp_Types = pkg_name.getComponentType_list().get(i); int btnHeight, btnWidth; double scale = 0.5; btnWidth = (int) (scale * (double) cmp_Types.getWidth()); btnHeight = (int) (scale * (double) cmp_Types.getHeight()); ImageIcon myIcon = new ImageIcon(cmp_Types.getType_Img()); BufferedImage bi = new BufferedImage(btnWidth, btnHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); g.scale(scale, scale); myIcon.paintIcon(null, g, 0, 0); g.dispose(); JButton strctButton = new JButton(new ImageIcon(bi)); strctButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { drawPad.add_componentType(cmp_Types, a); taskbar.setText("Click to add a component"); } }); panel.add(strctButton); } panel.validate(); // Updates the Panel }