标签:java ui编程 jframe add string end import ring icon
1 package com.kuang.lesson05; 2 3 import javax.swing.*; 4 import java.awt.*; 5 import java.net.URL; 6 7 public class JButtonDemo02 extends JFrame { 8 9 public JButtonDemo02(){ 10 Container container=this.getContentPane(); 11 //将一个图片变为图标 12 URL resource=JButtonDemo01.class.getResource("332556.jpg"); 13 Icon icon=new ImageIcon(resource); 14 15 //单选框 16 JRadioButton radioButton1=new JRadioButton("JRadioButton01"); 17 JRadioButton radioButton2=new JRadioButton("JRadioButton02"); 18 JRadioButton radioButton3=new JRadioButton("JRadioButton03"); 19 20 //由于单选框只能选择一个,分组,一个组中只能选择一个 21 ButtonGroup group=new ButtonGroup(); 22 group.add(radioButton1); 23 group.add(radioButton2); 24 group.add(radioButton3); 25 26 container.add(radioButton1,BorderLayout.CENTER); 27 container.add(radioButton2,BorderLayout.NORTH); 28 container.add(radioButton3,BorderLayout.SOUTH); 29 30 this.setVisible(true); 31 this.setSize(500,300); 32 this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 33 } 34 35 public static void main(String[] args) { 36 new JButtonDemo02(); 37 } 38 }
1 package com.kuang.lesson05; 2 3 import javax.swing.*; 4 import java.awt.*; 5 import java.net.URL; 6 7 public class JButtonDemo02 extends JFrame { 8 9 public JButtonDemo02(){ 10 Container container=this.getContentPane(); 11 //将一个图片变为图标 12 URL resource=JButtonDemo01.class.getResource("332556.jpg"); 13 Icon icon=new ImageIcon(resource); 14 15 //单选框 16 JRadioButton radioButton1=new JRadioButton("JRadioButton01"); 17 JRadioButton radioButton2=new JRadioButton("JRadioButton02"); 18 JRadioButton radioButton3=new JRadioButton("JRadioButton03"); 19 20 container.add(radioButton1,BorderLayout.CENTER); 21 container.add(radioButton2,BorderLayout.NORTH); 22 container.add(radioButton3,BorderLayout.SOUTH); 23 24 this.setVisible(true); 25 this.setSize(500,300); 26 this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 27 } 28 29 public static void main(String[] args) { 30 new JButtonDemo02(); 31 } 32 }
1 package com.kuang.lesson05; 2 3 import javax.swing.*; 4 import java.awt.*; 5 import java.net.URL; 6 7 public class JButtonDemo03 extends JFrame { 8 9 public JButtonDemo03(){ 10 Container container=this.getContentPane(); 11 //将一个图片变为图标 12 URL resource=JButtonDemo01.class.getResource("332556.jpg"); 13 Icon icon=new ImageIcon(resource); 14 15 //多选框 16 JCheckBox checkBox01=new JCheckBox("checkBox01"); 17 JCheckBox checkBox02=new JCheckBox("checkBox02"); 18 19 container.add(checkBox01,BorderLayout.NORTH); 20 container.add(checkBox02,BorderLayout.SOUTH); 21 22 this.setVisible(true); 23 this.setSize(500,300); 24 this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 25 } 26 27 public static void main(String[] args) { 28 new JButtonDemo03(); 29 } 30 }
标签:java ui编程 jframe add string end import ring icon
原文地址:https://www.cnblogs.com/clblogs/p/14664707.html