首页 / JAVA / 【Java】图形界面设计实战练习
【Java】图形界面设计实战练习
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了【Java】图形界面设计实战练习,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4358字,纯文字阅读大概需要7分钟。
内容图文
![【Java】图形界面设计实战练习](/upload/InfoBanner/zyjiaocheng/604/4a334e0ddc154b8fba9e2b5e9d1b179f.jpg)
实例一
代码:
package Gui;
import javax.swing.*;
import java.awt.*;
public class MyFrame extends JFrame {
JPanel jP1,jp2,jp3;
JLabel label1,label2;
JButton button1,button2;
JTextField text;
JPasswordField password;
public static void main(String[] args) {
MyFrame myFrame = new MyFrame();
}
public MyFrame(){
init();
setTitle("登录界面");
setBounds(300,300,250,150);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void init(){
setLayout(new GridLayout(3,1));
jP1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
label1 = new JLabel("用户名");
label2 = new JLabel("密 码");
text = new JTextField(10);
password = new JPasswordField(10);
button1 = new JButton("登录");
button2 = new JButton("取消");
jP1.add(label1);
jP1.add(text);
jp2.add(label2);
jp2.add(password);
jp3.add(button1);
jp3.add(button2);
add(jP1);
add(jp2);
add(jp3);
}
}
实例二
package Gui;
import javax.swing.*;
import java.awt.*;
public class MyFrame extends JFrame {
JPanel jp1,jp2,jp3;
JCheckBox checkBox1,checkBox2,checkBox3;
ButtonGroup group;
JRadioButton radioM,radioF;
JLabel label1,label2;
JButton button1,button2;
public static void main(String[] args) {
MyFrame myFrame = new MyFrame();
}
public MyFrame(){
init();
setTitle("用户注册界面");
setBounds(300,300,300,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void init(){
setLayout(new GridLayout(3,1));
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
label1 = new JLabel("你喜欢的运动");
label2 = new JLabel("你的性别");
checkBox1 = new JCheckBox("足球");
checkBox2= new JCheckBox("篮球");
checkBox3 = new JCheckBox("网球");
radioM = new JRadioButton("男");
radioF = new JRadioButton("女");
button1 = new JButton("注册用户");
button2 = new JButton("取消用户");
group = new ButtonGroup();
group.add(radioM);
group.add(radioF);
jp1.add(label1);
jp1.add(checkBox1);
jp1.add(checkBox2);
jp1.add(checkBox3);
jp2.add(label2);
jp2.add(radioM);
jp2.add(radioF);
jp3.add(button1);
jp3.add(button2);
add(jp1);
add(jp2);
add(jp3);
}
}
实例三
代码:
package Gui;
import javax.swing.*;
import java.awt.*;
public class MyFrame extends JFrame {
JPanel jp1,jp2,jp3;
JLabel label1,label2;
JComboBox comboBox;
JList list;
JScrollPane jScrollPane;
public static void main(String[] args) {
MyFrame myFrame = new MyFrame();
}
public MyFrame(){
init();
setTitle("下拉框练习");
setBounds(300,300,300,300);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void init(){
setLayout(new GridLayout(3,1));
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
label1 = new JLabel("你的籍贯是");
label2 = new JLabel("你喜欢旅游的地区是");
String []str1 = {"北京","上海","天津","重庆","江苏"};
comboBox = new JComboBox(str1);
String []str2 = {"黄山","故宫","长城","九寨沟","天安门","火星"};
list = new JList(str2);
list.setVisibleRowCount(1);
jScrollPane = new JScrollPane(list);
jp1.add(label1);
jp1.add(comboBox);
jp2.add(label2);
jp2.add(jScrollPane);
add(jp1);
add(jp3);
add(jp2);
}
}
实例四
代码:
package Gui;
import javax.swing.*;
import java.awt.*;
public class MyFrame extends JFrame {
JSplitPane jSplitPane;
JList list;
JLabel label;
public static void main(String[] args) {
MyFrame myFrame = new MyFrame();
}
public MyFrame(){
init();
setBounds(300,300,400,300);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void init(){
String []words = {"boy","gril","bird","box"};
list = new JList(words);
label = new JLabel(new ImageIcon("idea_test/2.jpg"));
jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,list,label);
jSplitPane.setOneTouchExpandable(true);
add(jSplitPane);
}
}
实例五
代码:
package Gui;
import javax.swing.*;
import java.awt.*;
public class MyFrame extends JFrame {
JSplitPane jSplitPane;
JTextArea area;
JTextField text;
JComboBox comboBox;
JButton button;
JPanel jPanel;
public static void main(String[] args) {
MyFrame myFrame = new MyFrame();
}
public MyFrame(){
init();
setTitle("QQ登录");
setBounds(300,300,300,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void init(){
String str[] = {"北京","上海","南京","合肥","洛阳","哈尔滨"};
comboBox = new JComboBox(str);
area = new JTextArea();
add(new JScrollPane(area));
text = new JTextField(10);
button = new JButton("发送");
jPanel = new JPanel();
jPanel.add(comboBox);
jPanel.add(text);
jPanel.add(button);
add(jPanel,BorderLayout.SOUTH);
//设置左上角小头像
setIconImage((new ImageIcon("idea_test\\2.jpg")).getImage());
}
}
内容总结
以上是互联网集市为您收集整理的【Java】图形界面设计实战练习全部内容,希望文章能够帮你解决【Java】图形界面设计实战练习所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。