Lập trình đồ họa với AWT - Phần 4
Số trang: 60
Loại file: pdf
Dung lượng: 332.70 KB
Lượt xem: 21
Lượt tải: 0
Xem trước 6 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Frame dùng để test các thành phần khácimport java.awt.*; import java.awt.event.*; public class ComponentTestFrame extends Frame implements WindowListener { public ComponentTestFrame(String title){ super(title); setBackground(SystemColor.control); setSize(400,300); setLocation(200,150); setLayout(new FlowLayout()); addWindowListener(this); }
Nội dung trích xuất từ tài liệu:
Lập trình đồ họa với AWT - Phần 4 CácthànhphầnAWT Frame dùng để test các thành phần khác import java.awt.*; import java.awt.event.*; public class ComponentTestFrame extends Frame implements WindowListener { public ComponentTestFrame(String title){ super(title); setBackground(SystemColor.control); setSize(400,300); setLocation(200,150); setLayout(new FlowLayout()); addWindowListener(this); } 25 CácthànhphầnAWT Frame dùng để test các thành phần khác public void windowClosing(WindowEvent e){ dispose(); System.exit(0); } public void windowActivated( WindowEvent e){} public void windowClosed(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowDeiconified( WindowEvent e){} public void windowDeactivated(WindowEvent e){} public void windowOpened(WindowEvent e){} } 26 CácthànhphầnAWT Một số phương thức của Frame Frame() Frame(String) Image getIconImage() MenuBar getMenuBar() String getTitle() Boolean isResizeable() setIconImage(Image) setMenuBar(MenuBar) setTitle(String) setVisible(boolean) 27 CácthànhphầnAWT GUIFrame import java.awt.*; import java.awt.event.*; public class GUIFrame extends Frame { public GUIFrame(String title){ super(title); setBackground(SystemColor.control); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ dispose(); System.exit(0); } }); } 28 CácthànhphầnAWT GUIFrame public void setVisible(boolean visible){ if(visible){ Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((d.width - getWidth())/2, (d.height -getHeight())/2); } super.setVisible(visible); } public static void main(String[] args){ GUIFrame frame = new GUIFrame(GUI Frame); frame.setSize(400,300); frame.setVisible(true); } } 29 CácthànhphầnAWT GUIFrame 30 CácthànhphầnAWT Label Dùng để hiển thị một đoạn văn bản trong một Container Các phương thức khởt tạo Label() Label(String text) Label(String text, alignment): alignment có thể nhận các giá trị Label.LEFT, Label.RIGHT, Label.CENTER Phương thức khác setFont(Font f) setText(String s) getText() getAlignment() 31 CácthànhphầnAWT Label import java.awt.*; public class LabelTest { public LabelTest() { Label l1 = new Label(Label); Label l2 = new Label(I am a label); l2.setFont(new Font(Timesroman, Font.BOLD, 18)); Label l3 = new Label(); l3.setText(I am disable); l3.setEnabled(false); Label l4 = new Label(Colored, right aligned, Label.RIG HT); l4.setForeground(Color.green); l4.setBackground(Color.black); ComponentTestFrame frame = new ComponentTestFrame(Label Test); 32 CácthànhphầnAWT Label frame.add(l1); frame.add(l2); frame.add(l3); frame.add(l4); frame.setVisible(true); } public static void main(String[] args) { LabelTest lt = new LabelTest(); } } 33 CácthànhphầnAWT TextComponent Là lớp cha của TextField và TextArea Một số phương thức của TextComponent getCaretPosition() getSelectedText() getSelectionStart() getSelectionEnd() getText(), setText() select(int, int) setCaretPosition(int) setEditable(boolean) setSelectionStart(int) setSelectionEnd(int) 34 CácthànhphầnAWT Một số phương thức TextField() TextField ...
Nội dung trích xuất từ tài liệu:
Lập trình đồ họa với AWT - Phần 4 CácthànhphầnAWT Frame dùng để test các thành phần khác import java.awt.*; import java.awt.event.*; public class ComponentTestFrame extends Frame implements WindowListener { public ComponentTestFrame(String title){ super(title); setBackground(SystemColor.control); setSize(400,300); setLocation(200,150); setLayout(new FlowLayout()); addWindowListener(this); } 25 CácthànhphầnAWT Frame dùng để test các thành phần khác public void windowClosing(WindowEvent e){ dispose(); System.exit(0); } public void windowActivated( WindowEvent e){} public void windowClosed(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowDeiconified( WindowEvent e){} public void windowDeactivated(WindowEvent e){} public void windowOpened(WindowEvent e){} } 26 CácthànhphầnAWT Một số phương thức của Frame Frame() Frame(String) Image getIconImage() MenuBar getMenuBar() String getTitle() Boolean isResizeable() setIconImage(Image) setMenuBar(MenuBar) setTitle(String) setVisible(boolean) 27 CácthànhphầnAWT GUIFrame import java.awt.*; import java.awt.event.*; public class GUIFrame extends Frame { public GUIFrame(String title){ super(title); setBackground(SystemColor.control); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ dispose(); System.exit(0); } }); } 28 CácthànhphầnAWT GUIFrame public void setVisible(boolean visible){ if(visible){ Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((d.width - getWidth())/2, (d.height -getHeight())/2); } super.setVisible(visible); } public static void main(String[] args){ GUIFrame frame = new GUIFrame(GUI Frame); frame.setSize(400,300); frame.setVisible(true); } } 29 CácthànhphầnAWT GUIFrame 30 CácthànhphầnAWT Label Dùng để hiển thị một đoạn văn bản trong một Container Các phương thức khởt tạo Label() Label(String text) Label(String text, alignment): alignment có thể nhận các giá trị Label.LEFT, Label.RIGHT, Label.CENTER Phương thức khác setFont(Font f) setText(String s) getText() getAlignment() 31 CácthànhphầnAWT Label import java.awt.*; public class LabelTest { public LabelTest() { Label l1 = new Label(Label); Label l2 = new Label(I am a label); l2.setFont(new Font(Timesroman, Font.BOLD, 18)); Label l3 = new Label(); l3.setText(I am disable); l3.setEnabled(false); Label l4 = new Label(Colored, right aligned, Label.RIG HT); l4.setForeground(Color.green); l4.setBackground(Color.black); ComponentTestFrame frame = new ComponentTestFrame(Label Test); 32 CácthànhphầnAWT Label frame.add(l1); frame.add(l2); frame.add(l3); frame.add(l4); frame.setVisible(true); } public static void main(String[] args) { LabelTest lt = new LabelTest(); } } 33 CácthànhphầnAWT TextComponent Là lớp cha của TextField và TextArea Một số phương thức của TextComponent getCaretPosition() getSelectedText() getSelectionStart() getSelectionEnd() getText(), setText() select(int, int) setCaretPosition(int) setEditable(boolean) setSelectionStart(int) setSelectionEnd(int) 34 CácthànhphầnAWT Một số phương thức TextField() TextField ...
Tìm kiếm theo từ khóa liên quan:
lập trình đồ họa lập trình với AWT Abstract Windowing Toolkit xử lý sự kiện thành phần đồ họaGợi ý tài liệu liên quan:
-
Đề cương chi tiết học phần Lập trình trên thiết bị di động (Mobile Programming) bậc đại học
13 trang 230 0 0 -
Bài giảng Lập trình Java căn bản: Chương 7 - ThS. Võ Đức Cẩm Hải
29 trang 190 0 0 -
Hướng dẫn lập trình OpenGL căn bản
33 trang 53 0 0 -
Bài giảng Kỹ thuật đồ họa và xử lý ảnh: Bài 1 - Nguyễn Hoài Anh
17 trang 42 1 0 -
40 trang 24 0 0
-
The art of software testing second edition p4
0 trang 22 0 0 -
Bài giảng Thiết kế và lập trình Web - Bài 4: JS – JavaScript
136 trang 22 0 0 -
58 trang 21 0 0
-
The art of software testing second edition p3
0 trang 20 0 0 -
The art of software testing second edition p7
0 trang 20 0 0