Suche senden
Hochladen
Applet 7 image_j_panel
•
0 gefällt mir
•
302 views
Nitigan Nakjuatong
Folgen
image_j_panel
Weniger lesen
Mehr lesen
Melden
Teilen
Melden
Teilen
1 von 5
Jetzt herunterladen
Downloaden Sie, um offline zu lesen
Empfohlen
Project Komputer Grafik
Project Komputer Grafik
HamimSuyuti
Dokumen
Dokumen
syahronirpl
Multmedia In Java
Multmedia In Java
Misheelle
Program project khusus
Program project khusus
kiuntoro
Java term project final
Java term project final
YongJinKwon8
Wartbare Web-Anwendungen mit Knockout.js und Model-View-ViewModel (MVVM)
Wartbare Web-Anwendungen mit Knockout.js und Model-View-ViewModel (MVVM)
adesso AG
Blog 4
Blog 4
iswan_di
Applet 7 image_j_panel
Applet 7 image_j_panel
Nitigan Nakjuatong
Empfohlen
Project Komputer Grafik
Project Komputer Grafik
HamimSuyuti
Dokumen
Dokumen
syahronirpl
Multmedia In Java
Multmedia In Java
Misheelle
Program project khusus
Program project khusus
kiuntoro
Java term project final
Java term project final
YongJinKwon8
Wartbare Web-Anwendungen mit Knockout.js und Model-View-ViewModel (MVVM)
Wartbare Web-Anwendungen mit Knockout.js und Model-View-ViewModel (MVVM)
adesso AG
Blog 4
Blog 4
iswan_di
Applet 7 image_j_panel
Applet 7 image_j_panel
Nitigan Nakjuatong
Applet 6 mouse_keyboard
Applet 6 mouse_keyboard
Nitigan Nakjuatong
New Assingment3 array2D
New Assingment3 array2D
Nitigan Nakjuatong
Applet 5 class_inheritance
Applet 5 class_inheritance
Nitigan Nakjuatong
Applet 5 class_inheritance
Applet 5 class_inheritance
Nitigan Nakjuatong
Array
Array
Nitigan Nakjuatong
662305 LAB13
662305 LAB13
Nitigan Nakjuatong
วิธีการกำหนดสิทธิให้กับ Directory
วิธีการกำหนดสิทธิให้กับ Directory
Nitigan Nakjuatong
662305 LAB12
662305 LAB12
Nitigan Nakjuatong
Applet 4 class_composition
Applet 4 class_composition
Nitigan Nakjuatong
662305 11
662305 11
Nitigan Nakjuatong
662305 10
662305 10
Nitigan Nakjuatong
662305 09
662305 09
Nitigan Nakjuatong
Applet 3 design_class_composition
Applet 3 design_class_composition
Nitigan Nakjuatong
662305 08
662305 08
Nitigan Nakjuatong
Applet 2 container and action_listener
Applet 2 container and action_listener
Nitigan Nakjuatong
662305 Lab7new
662305 Lab7new
Nitigan Nakjuatong
Assingment3 array2 d
Assingment3 array2 d
Nitigan Nakjuatong
Lab 6 new
Lab 6 new
Nitigan Nakjuatong
Array2D
Array2D
Nitigan Nakjuatong
Method part2
Method part2
Nitigan Nakjuatong
Control structure
Control structure
Nitigan Nakjuatong
Method JAVA
Method JAVA
Nitigan Nakjuatong
Weitere ähnliche Inhalte
Andere mochten auch
Applet 6 mouse_keyboard
Applet 6 mouse_keyboard
Nitigan Nakjuatong
New Assingment3 array2D
New Assingment3 array2D
Nitigan Nakjuatong
Applet 5 class_inheritance
Applet 5 class_inheritance
Nitigan Nakjuatong
Applet 5 class_inheritance
Applet 5 class_inheritance
Nitigan Nakjuatong
Array
Array
Nitigan Nakjuatong
662305 LAB13
662305 LAB13
Nitigan Nakjuatong
Andere mochten auch
(6)
Applet 6 mouse_keyboard
Applet 6 mouse_keyboard
New Assingment3 array2D
New Assingment3 array2D
Applet 5 class_inheritance
Applet 5 class_inheritance
Applet 5 class_inheritance
Applet 5 class_inheritance
Array
Array
662305 LAB13
662305 LAB13
Mehr von Nitigan Nakjuatong
วิธีการกำหนดสิทธิให้กับ Directory
วิธีการกำหนดสิทธิให้กับ Directory
Nitigan Nakjuatong
662305 LAB12
662305 LAB12
Nitigan Nakjuatong
Applet 4 class_composition
Applet 4 class_composition
Nitigan Nakjuatong
662305 11
662305 11
Nitigan Nakjuatong
662305 10
662305 10
Nitigan Nakjuatong
662305 09
662305 09
Nitigan Nakjuatong
Applet 3 design_class_composition
Applet 3 design_class_composition
Nitigan Nakjuatong
662305 08
662305 08
Nitigan Nakjuatong
Applet 2 container and action_listener
Applet 2 container and action_listener
Nitigan Nakjuatong
662305 Lab7new
662305 Lab7new
Nitigan Nakjuatong
Assingment3 array2 d
Assingment3 array2 d
Nitigan Nakjuatong
Lab 6 new
Lab 6 new
Nitigan Nakjuatong
Array2D
Array2D
Nitigan Nakjuatong
Method part2
Method part2
Nitigan Nakjuatong
Control structure
Control structure
Nitigan Nakjuatong
Method JAVA
Method JAVA
Nitigan Nakjuatong
Set putty to use numeric keyboard in pico
Set putty to use numeric keyboard in pico
Nitigan Nakjuatong
Putty basic setting
Putty basic setting
Nitigan Nakjuatong
Mehr von Nitigan Nakjuatong
(18)
วิธีการกำหนดสิทธิให้กับ Directory
วิธีการกำหนดสิทธิให้กับ Directory
662305 LAB12
662305 LAB12
Applet 4 class_composition
Applet 4 class_composition
662305 11
662305 11
662305 10
662305 10
662305 09
662305 09
Applet 3 design_class_composition
Applet 3 design_class_composition
662305 08
662305 08
Applet 2 container and action_listener
Applet 2 container and action_listener
662305 Lab7new
662305 Lab7new
Assingment3 array2 d
Assingment3 array2 d
Lab 6 new
Lab 6 new
Array2D
Array2D
Method part2
Method part2
Control structure
Control structure
Method JAVA
Method JAVA
Set putty to use numeric keyboard in pico
Set putty to use numeric keyboard in pico
Putty basic setting
Putty basic setting
Applet 7 image_j_panel
1.
การใชงาน Image และ
JPanel ssc พื้นฐานการใชงาน ImageIcon ตัวอยางหนาจอการทำงาน (http://202.44.47.108/~ssc/image-jpanel/testImageIcon.html) testImageIcon.html <html> ! <body> <h1>Test ImageIcon</h1> <h3>Create by: 5366261111 Supaporn Simcharoen IT1-RC</h3> ! ! <applet code="testImageIcon.class" height="350" width="600"> ! ! </applet> ! </body> </html> testImageIcon.java ขั้นตอนที่ 1 สราง Class พรอมกับ import package ที่ตองใช และสราง Method ที่นาจะมี import java.awt.*; import javax.swing.*; public class testImageIcon extends JApplet { ! public void init () { ! } ! public void paint(Graphics g) { ! } } ขั้นตอนที่ 2 ประกาศตัวแปร ImageIcon private ImageIcon image1, image2, image3; ขั้นตอนที่ 3 สราง ImageIcon ขึ้นมา ! public void init() ! { ! ! image1 = new ImageIcon( getClass().getResource("/htb-8.png") ); ! ! image2 = new ImageIcon( getClass().getResource("/htb-16.png") ); ! ! image3 = new ImageIcon( getClass().getResource("/htb-35.png") ); ! } ขั้นตอนที่ 4 แสดงผล ImageIcon ออกมา ! public void paint( Graphics g ) { ! ! image1.paintIcon( this, g, 0, 0 ); ! ! image2.paintIcon( this, g, 160, 0 ); ! ! image3.paintIcon( this, g, 320, 0 ); Note :: ................................................................ ! ! g.setFont(new Font("Tahoma",Font.BOLD, 14)); ! ! g.setColor(Color.BLUE); ! ! g.drawString("Width = " + image1.getIconWidth() + " pixel", 10, 180); ! ! g.drawString("Height = " + image1.getIconHeight() + " pixel", 10, 200); Note :: ................................................................ ! ! g.drawString("Width = " + image2.getIconWidth() + " pixel", 170, 180); ! ! g.drawString("Height = " + image2.getIconHeight() + " pixel", 170, 200); ! ! g.drawString("Width = " + image3.getIconWidth() + " pixel", 330, 260); ! ! g.drawString("Height = " + image3.getIconHeight() + " pixel", 330, 280); ! } ขั้นตอนที่ 5 ทดลอง Compile และ Run ผล Page 1 of 5
2.
การใชงาน ImageIcon และ
JPanel แบบ Composition ตัวอยางหนาจอการทำงาน (http://202.44.47.108/~ssc/image-jpanel/testImageJPanel.html) JPanel คือ ................................................. ............................................................................. ............................................................................. ............................................................................. ............................................................................. ............................................................................. Picture.java import java.awt.*; import javax.swing.*; public class Picture { ! private ImageIcon image; ! private int x, y; ! public Picture(String fname) { ! ! image = new ImageIcon(getClass().getResource(fname)); ! } ! public void draw( JPanel jPanel ) { ! ! image.paintIcon( jPanel , jPanel.getGraphics(), x, y ); ! } ! public void position(int x, int y) { ! ! this.x = x; ! ! this.y = y; ! } ! public void clear(JPanel jPanel) { ! ! jPanel.paint(jPanel.getGraphics()); ! } } Class Picture มีไวเพื่อ ......................................................................................................................................................... testImageJPanel.html <html> ! <body> <h1>Test Image and JPanel</h1> <h3>Create by: 5366261111 Supaporn Simcharoen IT1-RC</h3> ! ! <applet code="testImageJPanel.class" height="350" width="500"> ! ! </applet> ! </body> </html> testImageJPanel.java ขั้นตอนที่ 1 สราง Class พรอมกับ import package ที่ตองใช และสราง Method ที่นาจะมี import java.awt.*; import javax.swing.*; import java.awt.event.*; public class testImageJPanel extends JApplet implements ActionListener{ ! public void init() { ! } ! public void paint( Graphics g ) { ! } ! public void actionPerformed(ActionEvent e) { ! } } ขั้นตอนที่ 2 ประกาศคาตางๆ ! private Picture image1, image2, image3; ! private JPanel guiPanel, graphicsPanel; ! private JButton btn1, btn2, btn3, btnShow, btnClear; ! private boolean isShow = false; ! private int imageNo; Page 2 of 5
3.
ขั้นตอนที่ 3 สรางคาเริ่มตน
! public void init() { ! ! Container c = getContentPane(); ! ! c.setLayout(new FlowLayout()); ! ! guiPanel = new JPanel(); ! ! guiPanel.setPreferredSize(new Dimension(500, 50)); ! ! guiPanel.setBorder( BorderFactory.createBevelBorder(0)); ! ! btn1 = new JButton("Flower1"); ! ! btn1.addActionListener(this); ! ! guiPanel.add(btn1); ! ! btn2 = new JButton("Flower2"); ! ! btn2.addActionListener(this); ! ! guiPanel.add(btn2); ! ! btn3 = new JButton("Flower3"); ! ! btn3.addActionListener(this); ! ! guiPanel.add(btn3); ! ! btnShow = new JButton("Show"); ! ! btnShow.addActionListener(this); ! ! guiPanel.add(btnShow); ! ! btnClear = new JButton("Clear"); ! ! btnClear.addActionListener(this); ! ! guiPanel.add(btnClear); ! ! graphicsPanel = new JPanel(); ! ! graphicsPanel.setPreferredSize(new Dimension(520, 260)); ! ! graphicsPanel.setBorder(BorderFactory.createBevelBorder(0)); ! ! c.add(guiPanel); ! ! c.add(graphicsPanel); ! ! loadImage(); ! } ! public void loadImage() ! { ! ! image1 = new Picture( "/htb-8.png" ); ! ! image2 = new Picture( "/htb-16.png" ); ! ! image3 = new Picture( "/htb-35.png" ); ! } ! public void paint( Graphics g ) ! { ! ! super.paint( g ); ! ! if (isShow) { ! ! ! switch( imageNo ) { ! ! ! ! case 1: ! ! ! ! ! image1.draw( graphicsPanel ); ! ! ! ! ! break; ! ! ! ! case 2: ! ! ! ! ! image2.draw( graphicsPanel ); ! ! ! ! ! break; ! ! ! ! case 3: ! ! ! ! ! image3.draw( graphicsPanel ); ! ! ! ! ! break; ! ! ! } ! ! } ! } ขั้นตอนที่ 4 สรางในสวนของการตรวจสอบการกระทำกับปุมตางๆ ! public void actionPerformed(ActionEvent e) { ! ! if (e.getSource() == btn1) imageNo = 1; ! ! else if (e.getSource() == btn2) imageNo = 2; ! ! else if (e.getSource() == btn3) imageNo = 3; ! ! else if (e.getSource() == btnShow) { ! ! ! if (isShow == true) { btnShow.setText("Not show"); } ! ! ! else { btnShow.setText("Show"); } ! ! ! isShow = !isShow; ! ! } ! ! else { ! ! ! imageNo = 0; ! ! ! image1.clear( graphicsPanel ); ! ! } ! ! repaint(); ! } ขั้นตอนที่ 5 ทดลอง Compile และ Run ผล Page 3 of 5
4.
การใชงาน ImageIcon และ
JPanel แบบ Inheritance กับ Timer ตัวอยางหนาจอการทำงาน (http://202.44.47.108/~ssc/image-jpanel/testAnimation.html) Animation.java import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.Timer; public class Animation extends JPanel implements ActionListener { ! private int width = 400; ! private int height = 400; ! private Timer time; ! private ImageIcon image[] = new ImageIcon[5]; ! private int imageNo = 0; ! private Color color; ! public Animation() { ! ! super(); ! ! setPreferredSize( new Dimension(width, height)); ! ! setBorder( BorderFactory.createBevelBorder(0)); ! ! time = new Timer(500, this); ! ! loadImage(); ! ! color = getBackground(); ! } ! public Animation(int w, int h) { ! ! super(); ! ! width = w; ! ! height = h; ! ! setPreferredSize( new Dimension(width, height)); ! ! setBorder( BorderFactory.createBevelBorder(0)); ! ! time = new Timer(100, this); ! ! loadImage(); ! ! color = getBackground(); ! } ! private void loadImage() { ! ! for(int n = 0; n < image.length ; n++) { ! ! ! image[n] = new ImageIcon(getClass().getResource("/images/htb-"+n+".png")); ! ! } ! } ! public void play() { ! ! time.start(); ! } ! public void stop() { ! ! time.stop(); ! } ! public void actionPerformed(ActionEvent e) { ! ! nextImage(); ! ! Graphics g = getGraphics(); ! ! g.setColor(color); ! ! g.fillRect( 1, 1, width, height); ! ! image[imageNo].paintIcon( this, getGraphics(), 1, 1); ! } ! public void nextImage() { ! ! imageNo++; ! ! if (imageNo == 5) { imageNo = 0; } ! } ! protected void paintComponent(Graphics g) { ! ! super.paintComponent(g); ! } } Method loadImage มีไวเพื่อ ................................................................................................................................................ ที่ Method actionPerformed มีการทำงานอะไรบาง ................................................................................................................ ............................................................................................................................................................................................. Page 4 of 5
5.
testAnimation.html <html> !
<body> <h1>Test Animation</h1> <h3>Create by: 5366261111 Supaporn Simcharoen IT1-RC</h3> ! ! <applet code="testAnimation.class" height="400" width="400"> ! ! </applet> ! </body> </html> testAnimation.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class testAnimation extends JApplet implements ActionListener { ! private Animation display; ! private JButton playBtn, stopBtn; ! public void init() { ! ! Container c = getContentPane(); ! ! c.setLayout(new FlowLayout()); ! ! ! ! playBtn = new JButton("Play"); ! ! playBtn.addActionListener(this); ! ! c.add(playBtn); ! ! ! ! stopBtn = new JButton("Stop"); ! ! stopBtn.addActionListener(this); ! ! c.add(stopBtn); ! ! ! ! display = new Animation(); ! ! c.add(display); ! } ! public void paint(Graphics g) { ! ! super.paint(g); ! } ! public void stop( ) { ! ! display.stop(); ! } ! public void actionPerformed(ActionEvent e) { ! ! if (e.getSource() == playBtn) { ! ! ! display.play(); ! ! ! playBtn.setEnabled(false); ! ! } ! ! else if (e.getSource() == stopBtn) { ! ! ! display.stop(); ! ! ! playBtn.setEnabled(true); ! ! } ! } } Page 5 of 5
Jetzt herunterladen