computer 版 (精华区)

发信人: arbo (arbo), 信区: program
标  题: java 笔记5
发信站: 听涛站 (2001年09月17日10:45:41 星期一), 站内信件

发信人: airforce1 (五湖废人), 信区: Java
标  题: java 笔记5
发信站: BBS 水木清华站 (Sun Apr  2 11:23:50 2000)

今天讲的是AWT
就是一些component
1. Button
Button b=new Button("button name");
b.addActionListener(this);
add(b);

public void actionPerformed(ActionEvent ae){
  ...
  String s=ae.getActionCommand();
  ....
}

note: can use b.setActionCommand("command.."); to change the action command

2.checkbox // use Checkbox Group to group the radio button
Frame f = new Frame("checkbox group");
CheckboxGroup cbg=new CheckboxGroup();
Checkbox one=new Checkbox("one",false,cbg);
Checkbox two= new Checkbox("two",false,cbg);
one.addItemListener(this);
two.....
f.add(one);'
f.add(two);

3 Choise
select one from list type

Frame f=new Frame("choice");
Choice c=new Choice();
c.add("first");
c.add("second");
c.add("third");
c.addItemListener(this);
f.add(c);

4. Canvas
use to draw , write text of receiver keyboad or mouse input
public class MyCanvas extends Canvas implements KeyListener{
...
...m.. main(){...}
public void keyTyped(KeyEvent ev){
...
}

5,6 Text Field and TextArea
single text or multiple line text
i just ask teacher about TextArea  , how to auto-wrap a long text,
he said have no way, just use program to control.
TextField f= new TextField("stirng",20);
f.addActionListner(this);
add(f);

7. list
List l=new List(4, true);
1.add("hello");
l.add("hee");

8,9 dialog, file dialog
FileDialog d=new FileDialog(parentFrame, "filedialog");
d.setVisible(ture);
string fname=d.getFile();

10, very usefule, Scrollpane
it is  associated witha container, provide a viewport to a larger
region and scrollabrs to manipulate .

Frame f=newFrame());
Panel p=new Panel();
ScrollPane sp=new ScrollPane();
p.setLayout(new GridLayout(3,4));
..
sp.add(p);
f.add(sp,"center");
...

11 Menu
Frame f=new Frame("menu bar");
MenuBar mb=new Menubar();
Menu m1=new Menu("file");
NenuItem mi=new MnuItem("New");
m1.add(mi);
f.setMenuBar(mb);

12 popupMenu
PopupMenu p=new PopupMenu("popup");

13 Visual Aspect
setForegroud();
setBackground()

Color c=new Color(r,g,b);

Font f=new Font("timesRoman",Font.PLAIN,14);

14 Printing
Frame f=new Frame("Print test");
Toolkit t=f.getToolkit();
PrintJob job=t.getPrintJob(f,"myprintjob",null);
graphics g=job.getGraphics();
f.printComponets(g);
g.dispose()  // submit page to printer
job.end();



--
--
※ 来源:·听涛站 tingtao.dhs.org·[FROM: 匿名天使的家] 
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:0.970毫秒