-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageDisplay.java
More file actions
66 lines (50 loc) · 1.28 KB
/
ImageDisplay.java
File metadata and controls
66 lines (50 loc) · 1.28 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ImageDisplay extends JFrame{
JLabel label;
JTextField name;
JButton display;
JPanel upperPanel;
public static void main(String[] args){
//JFrame frame=new JFrame("The Evolving Project");
ImageDisplay img=new ImageDisplay();
//frame.add(img);
img.setSize(800,600);
img.setVisible(true);
img.setDefaultCloseOperation(EXIT_ON_CLOSE);
img.setResizable(false);
}
ImageDisplay()
{
super("The Evolving Project");
label=new JLabel("Enter your username");
name=new JTextField(15);
display=new JButton("Display Image");
DrawPanel panel=new DrawPanel();
display.addActionListener(panel);
upperPanel=new JPanel();
setLayout(new BorderLayout());
upperPanel.add(label);
upperPanel.add(name);
upperPanel.add(display);
add(upperPanel,BorderLayout.NORTH);
add(panel,BorderLayout.CENTER);
}
private class DrawPanel extends JPanel implements ActionListener{
Image image;
public void actionPerformed(ActionEvent e)
{
String text=name.getText().trim();
image=new ImageIcon(text).getImage();
repaint();
}
public void paintComponent(Graphics g)
{
setBackground(Color.WHITE);
g.setColor(Color.WHITE);
g.fillRect(10,10,800,600);
g.drawImage(image,10,10,this);
}
}
}