-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppExample.java
67 lines (64 loc) · 2.53 KB
/
AppExample.java
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
66
67
// application example, no copyright claimed, license: https://www.apache.org/licenses/LICENSE-2.0
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;
public class AppExample {
public static void main(String avg[]) throws IOException
{
String appName = "AppExample";
String imgFilename = "marsduke.png";
JLabel textLabel = new JLabel("<html>Spirit Mars Rover, Pancam, "
+ "Sol 120, 2004-05-05, ID 2P137011382EFF4000P2563L5M1</html>");
String links[] = {
"https://areo.info/mer/spirit/120",
"https://mars.nasa.gov/mer/gallery/all/spirit_p120.html"
};
JLabel linkLabels[] = {
new JLabel("<html>Color image: <a href='"
+ links[0] + "'>" + links[0] + "</a></html>"),
new JLabel("<html>Raw image, NASA / JPL-Caltech: <a href='"
+ links[1] + "'>" + links[1] + "</a></html>")
};
int space = 10;
String appDir = AppExample.class.getProtectionDomain().getCodeSource().getLocation().getPath();
if (appDir.endsWith(".jar"))
{
appDir = new File(appDir).getParent();
}
BufferedImage img = ImageIO.read(new File(appDir, imgFilename));
JFrame frame=new JFrame(appName);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createEmptyBorder(space, space, space, space));
ImageIcon icon=new ImageIcon(img);
JLabel iconLabel=new JLabel();
iconLabel.setIcon(icon);
panel.add(iconLabel);
panel.add(Box.createRigidArea(new Dimension(0, space)));
panel.add(textLabel);
for (int i=0; i<2; i++) {
String link = links[i];
linkLabels[i].setCursor(new Cursor(Cursor.HAND_CURSOR));
linkLabels[i].addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent ev) {
try {
Desktop.getDesktop().browse(new URI(link));
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
panel.add(linkLabels[i]);
}
frame.getContentPane().add(panel);
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}