In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use the construction method of Java Swing". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use Java Swing.
Introduction
Now with the rapid development of science and technology, a lot of things can be done through the Internet, among which doing exercises online, I believe many friends have experienced it. When doing exercises on the Internet, we will always encounter some multiple-choice questions, multiple-choice questions and multiple-choice questions, single-choice can only choose one, and multiple-choice can choose one or more, or even the function of all-choice.
Common Construction methods of JRadioButton
JRadioButton () is used to create a radio button with nothing.
JRadioButton (Icon icon) is used to create an image-only radio button
JRadioButton (Icon icon,boolean selected) is used to create radio buttons with images and selected states.
JRadioButton (String text) is used to create text-only radio buttons
JRadioButton (String text,boolean selected) is used to create radio buttons with text and selection.
JRadioButton (String text,Icon icon) is used to create radio buttons with text and images.
JRadioButton (String text,Icon icon,boolean selected) is used to create graphical, textual and stateful radio buttons.
Specific examples: import javax.swing.*;import java.awt.*;public class Demo01 {public static void main (String [] args) {JFrame jf=new JFrame ("use of JRadioButton"); / / create a window entitled "JRadioButton" JPanel jp=new JPanel (); JLabel jl=new JLabel ("which country do you like best?") ; JRadioButton rb1=new JRadioButton ("China No.1", true); JRadioButton rb2=new JRadioButton ("Freedom America"); JRadioButton rb3=new JRadioButton ("Romantic France"); JRadioButton rb4=new JRadioButton ("Cosmic South Korean"); jl.setFont (new Font ("Song style", Font.BOLD, 20); ButtonGroup btns=new ButtonGroup (); btns.add (rb1); btns.add (rb2); btns.add (rb3) Btns.add (rb4); jp.add (jl); jp.add (rb1); jp.add (rb2); jp.add (rb3); jp.add (rb4); jf.add (jp); jf.setBounds (100,100,800,600); / / set the coordinates and size of the window jf.setDefaultCloseOperation (WindowConstants.EXIT_ON_CLOSE) / / exit the program jf.setVisible (true) when the setting window closes; / / set the window to be visible}}
Note: if the options for a category are not placed in the same ButtonGroup, the following occurs.
Common Construction methods of JCheckBox
JCheckBox () is used to create a check box that has nothing and has not been selected.
JCheckBox (String text) is used to create a check box for the specified text content.
JCheckBox (String text, Boolean selected) is used to create a specified text content and to assign a check box to the selection status.
Specific examples: import javax.swing.*;import java.awt.*;public class Demo02 {public static void main (String [] args) {JFrame jf=new JFrame ("use of JCheckBox"); / / create a window jf.setBounds titled "JCheckBox" (100,100,800,600); / / set the coordinates and size of the window JPanel jp=new JPanel (); / / JLabel jl=new JLabel ("who is the most handsome in the world?") ; jl.setFont (new Font (Song style, Font.BOLD,20); JCheckBox jcb1=new JCheckBox (Editor, true); / / create check boxes JCheckBox jcb2=new JCheckBox (Reader, true); JCheckBox jcb3=new JCheckBox (Jack Ma); JCheckBox jcb4=new JCheckBox (Ma Huateng); JCheckBox jcb5=new JCheckBox (Wang Jianlin); JCheckBox jcb6=new JCheckBox (Lei Jun) JCheckBox jcb7=new JCheckBox (Bill Gates); jp.add (jl); jp.add (jcb1); jp.add (jcb2); jp.add (jcb3); jp.add (jcb4); jp.add (jcb5); jp.add (jcb6); jp.add (jcb7); jf.add (jp); jf.setDefaultCloseOperation (WindowConstants.EXIT_ON_CLOSE) / / setting window closes namely exit program jf.setVisible (true); / / setting window visible}} Thank you for reading, above is the content of "how to use the construction method of Java Swing". After the study of this article, I believe you have a deeper understanding of how to use the construction method of Java Swing, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.