-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLauncher.java
More file actions
94 lines (81 loc) · 2.92 KB
/
Copy pathLauncher.java
File metadata and controls
94 lines (81 loc) · 2.92 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
public class Launcher {
final int FRAME_WIDTH = 500;
final int FRAME_HEIGHT = 800;
Launcher(){
//get directory of jar
File dir = null;
try {
dir = new File(Launcher.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile();
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
final String path = dir.getPath();
//make a filter to find all vpks and then use it
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File f, String name)
{
return name.endsWith(".vpk");
}
};
File[] vpks = dir.listFiles(filter);
//create date formate
SimpleDateFormat dateformat = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
//fill table of vpks and adds labels
Object[][] vpkrows = new Object[vpks.length][3];
for (int i = 0; i < vpks.length; i++) {
vpkrows[i][0] = vpks[i].getName();
vpkrows[i][1] = dateformat.format(vpks[i].lastModified());
vpkrows[i][2] = vpks[i].length()/(1024) + " kb";
}
Object[] labels = {"Title", "Last Modified", "Size"};
//make data displayable and prettier
JTable vpktable = new JTable(vpkrows, labels);
vpktable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
TableColumnModel columnmodel = vpktable.getColumnModel();
columnmodel.getColumn(0).setPreferredWidth((int)(FRAME_WIDTH*.85));
columnmodel.getColumn(1).setPreferredWidth((int)(FRAME_WIDTH*.10));
columnmodel.getColumn(2).setPreferredWidth((int)(FRAME_WIDTH*.05));
JScrollPane tablepane = new JScrollPane(vpktable);
//initialize button
JButton startbutton = new JButton("Start Map");
//create jpanel and populate it
JPanel panel = new JPanel(new BorderLayout());
panel.add(tablepane);
panel.add(startbutton, BorderLayout.SOUTH);
//create the actual window
JFrame frame = new JFrame("HLALauncher");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
frame.setSize(FRAME_HEIGHT, FRAME_WIDTH);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
//add action listener to button that launches the exe
startbutton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(vpktable.getValueAt(vpktable.getSelectedRow(), 0) != null){
try {
Runtime.getRuntime().exec("cmd /c start \"\" \"" + path + "\\hlalauncher.exe\" \"" +
path + "\\" + vpktable.getValueAt(vpktable.getSelectedRow(), 0) + "\"");
System.exit(0);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
});
}
public static void main(String[] args) {
new Launcher();
}
}