잡동사니에도 사랑을

[21.08.26] JButtonEx 본문

JAVA_SE/13_swing

[21.08.26] JButtonEx

luvforjunk 2021. 8. 29. 21:04
728x90
반응형

package swing;

 

import java.awt.Container;

import java.awt.GridLayout;

 

import javax.swing.ButtonGroup;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JRadioButton;

 

class JButtonEx extends JFrame {

         private Icon icon1 = new ImageIcon("image/너부리.jpg");

         private Icon icon2 = new ImageIcon("image/보노보노.png");

         private Icon icon3 = new ImageIcon("image/포로리.jpg");

         private Icon icon4 = new ImageIcon("image/피카츄.jpg");

         private JRadioButton[] jb = new JRadioButton[4];

         private ButtonGroup bg = new ButtonGroup();

 

         public JButtonEx() {

                  super("Test");

                  Container con = this.getContentPane();

                  con.setLayout(new GridLayout(2, 2));

                  for (int i = 0; i < 4; i++) {

                           jb[i] = new JRadioButton(i + 1 + " 버튼", icon1);

                           con.add(jb[i]);

                           jb[i].setToolTipText(i + 1 + "번째 버튼이다. 눌러...");

                           jb[i].setMnemonic(i + 49);

                           jb[i].setRolloverIcon(icon2);

                           jb[i].setPressedIcon(icon3);

                           jb[i].setSelectedIcon(icon4);

                           bg.add(jb[i]);

 

                  }

                  pack();

                  setVisible(true);

         }

 

         public static void main(String[] args) {

                  new JButtonEx();

         }

}

 

728x90
반응형

'JAVA_SE > 13_swing' 카테고리의 다른 글

[21.08.26] JTableEx2  (0) 2021.08.29
[21.08.26] JTableEx  (0) 2021.08.29
[21.08.26] JListEx  (0) 2021.08.29