-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImages.java
More file actions
51 lines (48 loc) · 1.3 KB
/
Images.java
File metadata and controls
51 lines (48 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JComponent;
import java.awt.Image;
import javax.swing.ImageIcon;
import java.awt.Graphics;
public class Main{
public static void main(String args[]){
EventQueue.invokeLater(()->{
JFrame frame=new JFrame();
frame.setTitle("Testing Image");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
});
}
}
class ImageFrame extends JFrame{
public ImageFrame(){
add(new ImageComponent());
pack();
}
}
class ImageComponent extends JComponent{
private static final int DEFAULT_WIDTH=1000;
private static final int DEFAULT_HEIGHT=1000;
private Image image;
public ImageComponent(){
image=new ImageIcon("lady.jpg").getImage();
}
public void paintComponent(Graphics g){
if(image == null) return;
int imageWidth=image.getWidth(this);
int imageHeight=image.getHeight(this);
g.drawImage(image,0,0,null);
for(int i =0;i*imageWidth<=getWidth();i++){
for(int j=0;j*imageHeight<=getHeight();j++){
if(i+j>0){
g.copyArea(0, 0, imageWidth,imageHeight,i*imageWidth,i*imageHeight);
}
}
}
}
public Dimension getPreferredSize(){
return new Dimension(DEFAULT_WIDTH,DEFAULT_HEIGHT);
}
}
//been working in this code