想接触一下swing,谁能给个入门的例子让我认识一下 如题 。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 此回复为自动发出,仅用于显示而已,并无任何其他特殊作用楼主【shisi0325】截止到2008-07-31 09:42:30的历史汇总数据(不包括此帖):发帖的总数量:48 发帖的总分数:1180 每贴平均分数:24 回帖的总数量:14 得分贴总数量:0 回帖的得分率:0% 结贴的总数量:44 结贴的总分数:1090 无满意结贴数:2 无满意结贴分:40 未结的帖子数:4 未结的总分数:90 结贴的百分比:91.67 % 结分的百分比:92.37 % 无满意结贴率:4.55 % 无满意结分率:3.67 % 值得尊敬取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=shisi0325 建议楼主去看看API,中文版的现在很多CHM做得很好了。SWING的基本控件跟AWT差不多,JFrame窗口,JButton按钮,JTextField文本输入框,JLabel标签,JTextArea文本区域,JMenu窗口菜单,还有强大的Layout布局,关于这方面的书本和电子图书都很多,一般的JAVA基础书上都有讲到! 入门的么?package com.zhangkai;import javax.swing.JFrame;public class TestJFrame extends JFrame { public TestJFrame() { setLocation(300,300);//显示位置 setSize(300,300);//大小 setTitle("第一个Swing!"); setVisible(true);//显示。 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭 } public static void main(String[] args) { new TestJFrame(); }}哦了。 import javax.swing.*;import java.awt.*;import java.awt.event.*;public class JavaSwing extends JFrame{ JButton jb=new JButton("jbutton"); public JavaSwing(){ jb.setSize(80,25); jb.setLocation(210,100); jb.addActionListener(new Al()); this.setLayout(null); this.add(jb); this.setDefaultCloseOperation(3); this.setVisible(true); this.setSize(500,200); this.setLocation(300,300); } class Al implements ActionListener{ public void actionPerformed(ActionEvent e){ JOptionPane.showInputDialog("输入你的名字"); } } public static void main (String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { } new JavaSwing(); }} 也!原来楼主是要例子啊!呵呵,补个例子!import java.awt.Color;import java.awt.Container;import java.awt.TextArea;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import javax.swing.JButton;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JTextField;public class System extends JFrame{ JLabel l; JButton b1,b2; JTextField t1; TextArea t2; Container c; JFileChooser fc; String filePath,targetPath,result; File selectedFile; System() { setTitle("aaa"); setBounds(350,300,440,410); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); input(); setVisible(true); } public void input(){ b1 = new JButton(); b1.setText("button1"); b2 = new JButton(); b2.setText("button2"); t1 = new JTextField(); t1.setText("text1"); t1.setEditable(false); t1.setBackground(Color.WHITE); l = new JLabel(); l.setText("txt2"); l.setVisible(false); t2 = new TextArea("",0,0,TextArea.SCROLLBARS_VERTICAL_ONLY); c = this.getContentPane(); c.setLayout(null); c.add(b1); c.add(b2); c.add(t1); c.add(l); c.add(t2); b1.setBounds(10, 10, 100, 25); b2.setBounds(10, 45, 100, 25); t1.setBounds(120, 10, 300, 25); l.setBounds(120, 45, 200, 25); t2.setBounds(10, 80, 410, 290); b1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { fc = new JFileChooser(); fc.setDialogTitle("choose"); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); if(JFileChooser.APPROVE_OPTION==fc.showOpenDialog(null)){ selectedFile = fc.getSelectedFile(); filePath = selectedFile.getAbsolutePath(); t1.setText(filePath); } } }); b2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(!("".equals(filePath)||filePath == null)){ //do something! t2.setText("succes"); l.setVisible(true); } else{ t2.setText("No choose"); } } }); } public static void main(String[] args) { new System(); }} import javax.swing.*;import java.awt.*;class MyFrame extends JFrame{ MyFrame(String title) { super(title); setLayout(new FlowLayout()); setBounds(50,50,600,300); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } }简单而有用的类 去这个网站吧:里面可以找到大部分java demo 当然包括:swing的了!http://www.java2s.com/ Swing Componentshttp://www.java2s.com/Code/Java/Swing-Components/CatalogSwing-Components.htm 菜鸟求叫!!java写MyQQ,登陆界面中的注册新用户跳链到一个注册网页怎么实现? 求高手给解答一下 java链接mysql数据库异常 J2SE学完学什么? Rcp,JFace都是对SWT进行封装? 两者间有什么区别? 问题:没有显示出错误,但是输不出自己想的要结果。 tomcat 连接池的一个超级bug!!! 求教Swing的问题 如何把一个字符串改成全角的字符串 请教!这个程序运行结果为什么会是这样? SQL Server 2000 JDBC applet连接数据库??? sql2005 连接问题? unsigned int 返回 long
楼主【shisi0325】截止到2008-07-31 09:42:30的历史汇总数据(不包括此帖):
发帖的总数量:48 发帖的总分数:1180 每贴平均分数:24
回帖的总数量:14 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:44 结贴的总分数:1090
无满意结贴数:2 无满意结贴分:40
未结的帖子数:4 未结的总分数:90
结贴的百分比:91.67 % 结分的百分比:92.37 %
无满意结贴率:4.55 % 无满意结分率:3.67 %
值得尊敬
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=shisi0325
package com.zhangkai;import javax.swing.JFrame;public class TestJFrame extends JFrame {
public TestJFrame() {
setLocation(300,300);//显示位置
setSize(300,300);//大小
setTitle("第一个Swing!");
setVisible(true);//显示。
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭
}
public static void main(String[] args) {
new TestJFrame();
}
}哦了。
import java.awt.*;
import java.awt.event.*;
public class JavaSwing extends JFrame{
JButton jb=new JButton("jbutton");
public JavaSwing(){
jb.setSize(80,25);
jb.setLocation(210,100);
jb.addActionListener(new Al());
this.setLayout(null);
this.add(jb);
this.setDefaultCloseOperation(3);
this.setVisible(true);
this.setSize(500,200);
this.setLocation(300,300);
}
class Al implements ActionListener{
public void actionPerformed(ActionEvent e){
JOptionPane.showInputDialog("输入你的名字");
}
}
public static void main (String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception ex) {
}
new JavaSwing();
}
}
import java.awt.Container;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;public class System extends JFrame{
JLabel l;
JButton b1,b2;
JTextField t1;
TextArea t2;
Container c;
JFileChooser fc;
String filePath,targetPath,result;
File selectedFile;
System() {
setTitle("aaa");
setBounds(350,300,440,410);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
input();
setVisible(true);
}
public void input(){
b1 = new JButton();
b1.setText("button1");
b2 = new JButton();
b2.setText("button2");
t1 = new JTextField();
t1.setText("text1");
t1.setEditable(false);
t1.setBackground(Color.WHITE);
l = new JLabel();
l.setText("txt2");
l.setVisible(false);
t2 = new TextArea("",0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
c = this.getContentPane();
c.setLayout(null);
c.add(b1);
c.add(b2);
c.add(t1);
c.add(l);
c.add(t2);
b1.setBounds(10, 10, 100, 25);
b2.setBounds(10, 45, 100, 25);
t1.setBounds(120, 10, 300, 25);
l.setBounds(120, 45, 200, 25);
t2.setBounds(10, 80, 410, 290);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
fc = new JFileChooser();
fc.setDialogTitle("choose");
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
if(JFileChooser.APPROVE_OPTION==fc.showOpenDialog(null)){
selectedFile = fc.getSelectedFile();
filePath = selectedFile.getAbsolutePath();
t1.setText(filePath);
}
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(!("".equals(filePath)||filePath == null)){
//do something!
t2.setText("succes");
l.setVisible(true);
}
else{
t2.setText("No choose");
}
}
});
}
public static void main(String[] args) {
new System();
}}
import java.awt.*;
class MyFrame extends JFrame
{
MyFrame(String title)
{
super(title);
setLayout(new FlowLayout());
setBounds(50,50,600,300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}简单而有用的类