JFrame小练习1
2015-09-20 22:37
127 查看
1.文本域组件
public class TestJTextArea {
public static void main(String[] args) {
JFrame jf=new JFrame("演示文本域");
JPanel jp=new JPanel();
JTextArea jta=new JTextArea("演示文本域,演示文本域,演示文本域",6,6);
jta.setLineWrap(true);
jp.add(jta);
jf.add(jp);
jf.setSize(200,200);
jf.setLocation(200,200);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
}
2.列表框
public class TestJTextArea {
public static void main(String[] args) {
JFrame jf=new JFrame("演示文本域");
JPanel jp=new JPanel();
JTextArea jta=new JTextArea("演示文本域,演示文本域,演示文本域",6,6);
jta.setLineWrap(true);
jp.add(jta);
jf.add(jp);
jf.setSize(200,200);
jf.setLocation(200,200);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
}
3.下拉列表框
import java.awt.FlowLayout;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class TestJComboBox extends AbstractListModel<String> implements ComboBoxModel<String>{
String selectedItem=null;
String[] listData={"现金支付","银行卡支付","支付宝支付"};
public String getElementAt(int index){
return listData[index];
}
public int getSize(){
return listData.length;
}
public Object getSelectedItem(){
return selectedItem;
}
public void setSelectedItem(Object arg0){
selectedItem=(String)arg0;
}
public int getIndex(){
for(int i=0;i<listData.length;i++){
if(listData[i].equals(getSelectedItem()))
return i;
}
return 0;
}
public static void main(String[] args) {
JFrame jf=new JFrame("演示下拉列表框");
jf.setSize(300,200);
jf.setLocation(200,200);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
jf.setLayout(new FlowLayout());
JLabel j1=new JLabel("请选择支付方式:");
jf.add(j1);
JComboBox<String>jcb=new JComboBox<>(new TestJComboBox());
jf.add(jcb);
}
}
public class TestJTextArea {
public static void main(String[] args) {
JFrame jf=new JFrame("演示文本域");
JPanel jp=new JPanel();
JTextArea jta=new JTextArea("演示文本域,演示文本域,演示文本域",6,6);
jta.setLineWrap(true);
jp.add(jta);
jf.add(jp);
jf.setSize(200,200);
jf.setLocation(200,200);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
}
2.列表框
public class TestJTextArea {
public static void main(String[] args) {
JFrame jf=new JFrame("演示文本域");
JPanel jp=new JPanel();
JTextArea jta=new JTextArea("演示文本域,演示文本域,演示文本域",6,6);
jta.setLineWrap(true);
jp.add(jta);
jf.add(jp);
jf.setSize(200,200);
jf.setLocation(200,200);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
}
3.下拉列表框
import java.awt.FlowLayout;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class TestJComboBox extends AbstractListModel<String> implements ComboBoxModel<String>{
String selectedItem=null;
String[] listData={"现金支付","银行卡支付","支付宝支付"};
public String getElementAt(int index){
return listData[index];
}
public int getSize(){
return listData.length;
}
public Object getSelectedItem(){
return selectedItem;
}
public void setSelectedItem(Object arg0){
selectedItem=(String)arg0;
}
public int getIndex(){
for(int i=0;i<listData.length;i++){
if(listData[i].equals(getSelectedItem()))
return i;
}
return 0;
}
public static void main(String[] args) {
JFrame jf=new JFrame("演示下拉列表框");
jf.setSize(300,200);
jf.setLocation(200,200);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
jf.setLayout(new FlowLayout());
JLabel j1=new JLabel("请选择支付方式:");
jf.add(j1);
JComboBox<String>jcb=new JComboBox<>(new TestJComboBox());
jf.add(jcb);
}
}
相关文章推荐
- Android网络图片的三级缓存
- 2、分支结构程序体验-项目1(正差值)
- 自定义集合双向链表
- 有限状态机与应用一例
- Python——类属性/实例属性
- 触发器学习笔记
- 微服务架构 如何影响传统的软件架构设计
- 云计算基本概念
- 2016年魅族Java研发面试总结
- Linux与windows的对比
- MySQL 局域网访问速度慢的问题
- iOS小文件的下载方式
- 如何让类似imagePicker以及MVMoview系统控件返回按钮显示中文
- 论文笔记《Superparsing: Scalable Nonparametric Image Parsing with Superpixels》
- 实践一:个人项目实践
- 白盒测试的几种覆盖方式
- 最简单的html+css三列布局
- Android集成友盟社会化分享
- 经典题目
- Cocoa消息处理流程