?? imagesloading.java
字號:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
class imageLoad extends Canvas {
Image img;
public imageLoad(Image img) {
this.img = img;
}
public void paint (Graphics g) {
if (img != null)
{
g.drawImage(img, 0, 0, 1000, 1000, this);
}
}
public void setImage (Image img){
this.img = img;
}
}
public class ImagesLoading implements ActionListener{
JFrame fr = new JFrame ("Image loading program Using awt");
Label Label1 = new Label("Label1 ");
Button Button1 = new Button("Click Here");
Image Image1;
imageLoad Canvas1;
FileDialog fd = new FileDialog(fr,"Open", FileDialog.LOAD);
void initialize (){
fr.setSize(500,500);
fr.setLocation(300,300);
fr.setBackground(Color.lightGray);
fr.setLayout(new FlowLayout());
fr.add(Label1);
fr.add(Button1);
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Button1.addActionListener(this);
Canvas1 = new imageLoad(null);
Canvas1.setSize(1000,1000);
fr.add(Canvas1);
fr.show();
}
void imageload () {
fd.show();
if(fd.getFile() == null){
Label1.setText("You have not chosen any image files yet");
}
else{
String d = (fd.getDirectory() + fd.getFile());
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image1 = toolkit.getImage(d);
Canvas1.setImage(Image1);
Canvas1.repaint();
}
}
public void windowClosing(WindowEvent e){
System.exit(0);
}
public void windowActivated(WindowEvent e){
}
public void windowClosed(WindowEvent e){
}
public void windowDeactivated(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
public void windowIconified(WindowEvent e){
}
public void windowOpened(WindowEvent e){
}
public void actionPerformed(ActionEvent event){
Button b = (Button)event.getSource();
if(b == Button1){
imageload();
}
}
public static void main(String args[]){
ImagesLoading a = new ImagesLoading();
a.initialize();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -