黑马程序员 图形化界面编程
2013-12-30 18:07
253 查看
----------------------
ASP.Net+Android+IOS开发、.Net培训、期待与您交流! ----------------------
GUI(Graphical User Interface)图形化界面编程
Java.Awt:Abstract Window ToolKit(抽象窗口工具包)
Javax.Swing:
图形化界面基本设置:
设置窗体大小:setSize(长,宽);
设置窗体位置:setLocation(距离左,距离上);setBounds(长,宽,距离左,距离上);
设置布局:setLayout(new FlowLayout());
使窗体可见:setVisible(true);
事件监听机制:
事件监听机制的特点:
1,事件源。
2,事件。
3,监听器。
4,事件处理。
事件源:就是awt包或者swing包中的那些图形界面组件。
事件:每一个事件源都有自己特有的对应事件和共性事件。
监听器:将可以触发某一个事件的动作(不只一个动作)都已经封装到了监听器中。
以上三者,在java中都已经定义好了。
直接获取其对象来用就可以了。
我们要做的事情是,就是对产生的动作进行处理
Eg:编写程序,练习图形化界面编程!
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class MyWindowDemo
{
private Frame f;
privateTextField tf;
private Buttonbut;
private TextAreata;
private Dialogd;
private Labellab;
private ButtonokBut;
MyWindowDemo()
{
init();
}
public voidinit()
{
f = newFrame("my window");
f.setBounds(300,100,600,500);
f.setLayout(newFlowLayout());
tf = newTextField(60);
but = new Button("转到");
ta = newTextArea(25,70);
d = newDialog(f,"提示信息-self",true);
d.setBounds(400,200,240,150);
d.setLayout(newFlowLayout());
lab = newLabel();
okBut = newButton("确定");
d.add(lab);
d.add(okBut);
f.add(tf);
f.add(but);
f.add(ta);
myEvent();
f.setVisible(true);
}
privatevoid myEvent()
{
okBut.addActionListener(newActionListener()
{
publicvoid actionPerformed(ActionEvent e)
{
d.setVisible(false);
}
});
d.addWindowListener(newWindowAdapter()
{
publicvoid windowClosing(WindowEvent e)
{
d.setVisible(false);
}
});
tf.addKeyListener(newKeyAdapter()
{
publicvoid keyPressed(KeyEvent e)
{
if(e.getKeyCode()==KeyEvent.VK_ENTER)
showDir();
}
});
but.addActionListener(newActionListener()
{
publicvoid actionPerformed(ActionEvent e)
{
showDir();
}
});
f.addWindowListener(newWindowAdapter()
{
publicvoid windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
private voidshowDir()
{
StringdirPath = tf.getText();
File dir =new File(dirPath);
if(dir.exists()&& dir.isDirectory())
{
ta.setText("");
String[]names = dir.list();
for(Stringname : names)
{
ta.append(name+"\r\n");
}
}
else
{
Stringinfo = "您输入的信息:"+dirPath+"是错误的。请重输";
lab.setText(info);
d.setVisible(true);
}
}
public staticvoid main(String[] args)
{
newMyWindowDemo();
}
}
菜单:
MenuBar 菜单整体;Menu 包含于MenuBar中;MenuItem包含于Menu中!
以上3个关系添加用add();
将MenuBar放进Frame中用setMenuBar();
FileDialog.LOAD:打开的mode
FileDialog.Save:保存的mode
----------------------
ASP.Net+Android+IOS开发、.Net培训、期待与您交流! ----------------------
ASP.Net+Android+IOS开发、.Net培训、期待与您交流! ----------------------
GUI(Graphical User Interface)图形化界面编程
Java.Awt:Abstract Window ToolKit(抽象窗口工具包)
Javax.Swing:
图形化界面基本设置:
设置窗体大小:setSize(长,宽);
设置窗体位置:setLocation(距离左,距离上);setBounds(长,宽,距离左,距离上);
设置布局:setLayout(new FlowLayout());
使窗体可见:setVisible(true);
事件监听机制:
事件监听机制的特点:
1,事件源。
2,事件。
3,监听器。
4,事件处理。
事件源:就是awt包或者swing包中的那些图形界面组件。
事件:每一个事件源都有自己特有的对应事件和共性事件。
监听器:将可以触发某一个事件的动作(不只一个动作)都已经封装到了监听器中。
以上三者,在java中都已经定义好了。
直接获取其对象来用就可以了。
我们要做的事情是,就是对产生的动作进行处理
Eg:编写程序,练习图形化界面编程!
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class MyWindowDemo
{
private Frame f;
privateTextField tf;
private Buttonbut;
private TextAreata;
private Dialogd;
private Labellab;
private ButtonokBut;
MyWindowDemo()
{
init();
}
public voidinit()
{
f = newFrame("my window");
f.setBounds(300,100,600,500);
f.setLayout(newFlowLayout());
tf = newTextField(60);
but = new Button("转到");
ta = newTextArea(25,70);
d = newDialog(f,"提示信息-self",true);
d.setBounds(400,200,240,150);
d.setLayout(newFlowLayout());
lab = newLabel();
okBut = newButton("确定");
d.add(lab);
d.add(okBut);
f.add(tf);
f.add(but);
f.add(ta);
myEvent();
f.setVisible(true);
}
privatevoid myEvent()
{
okBut.addActionListener(newActionListener()
{
publicvoid actionPerformed(ActionEvent e)
{
d.setVisible(false);
}
});
d.addWindowListener(newWindowAdapter()
{
publicvoid windowClosing(WindowEvent e)
{
d.setVisible(false);
}
});
tf.addKeyListener(newKeyAdapter()
{
publicvoid keyPressed(KeyEvent e)
{
if(e.getKeyCode()==KeyEvent.VK_ENTER)
showDir();
}
});
but.addActionListener(newActionListener()
{
publicvoid actionPerformed(ActionEvent e)
{
showDir();
}
});
f.addWindowListener(newWindowAdapter()
{
publicvoid windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
private voidshowDir()
{
StringdirPath = tf.getText();
File dir =new File(dirPath);
if(dir.exists()&& dir.isDirectory())
{
ta.setText("");
String[]names = dir.list();
for(Stringname : names)
{
ta.append(name+"\r\n");
}
}
else
{
Stringinfo = "您输入的信息:"+dirPath+"是错误的。请重输";
lab.setText(info);
d.setVisible(true);
}
}
public staticvoid main(String[] args)
{
newMyWindowDemo();
}
}
菜单:
MenuBar 菜单整体;Menu 包含于MenuBar中;MenuItem包含于Menu中!
以上3个关系添加用add();
将MenuBar放进Frame中用setMenuBar();
FileDialog.LOAD:打开的mode
FileDialog.Save:保存的mode
----------------------
ASP.Net+Android+IOS开发、.Net培训、期待与您交流! ----------------------
相关文章推荐
- 黑马程序员——自学笔记13(图形化界面编程2—事件监听机制)
- 黑马程序员——图形化界面编程GUI
- 黑马程序员_JAVA学习日记_JAVA中图形化界面GUI编程
- 黑马程序员-图形化界面和网络编程
- 黑马程序员——Java基础---图形化界面编程
- 黑马程序员——第十五篇:线程池、单例设计模式、图形化界面、网络编程
- 黑马程序员—JAVA基础—GUI(图形化界面编程)
- 黑马程序员------图形化界面
- 黑马程序员_图形化界面
- 黑马程序员_07Java图形化界面GUI知识总结
- 黑马程序员_图形界面编程
- 黑马程序员_Java第22天知识总结_创建图形化界面_事件监听机制_双击执行的jar包
- 黑马程序员-图形化界面的课堂笔记
- 黑马程序员--------------java基础----------------- 图形化界面
- 黑马程序员------毕老师视频笔记第22天-----图形化编程(GUI)(1)
- 黑马程序员---图形化界面(GUI)
- 黑马程序员----java基础图形化界面GUI
- 黑马程序员 图形化界面
- 黑马程序员java学习笔记——GUI图形化界面
- 黑马程序员:Java基础总结----GUI图形化界面