-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.java
149 lines (121 loc) · 4.37 KB
/
GUI.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package xml;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JTable;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableCellRenderer;
public class GUI {
private JFrame frame;
private JTextField textField;
private JTable table;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
GUI window = new GUI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public GUI() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 1300, 700);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textField = new JTextField();
textField.setColumns(50);
Object[][] info = new Object[700][9];
logic l = new logic();
String[] header={"ID", "Name", "Summary", "Typical severity","Typical likelihood of exploit"," Attack skills or knowledge required","Related weakness","CIA impact", "content"};
JButton btnNewButton = new JButton("Search");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String keyword = textField.getText();
l.searchxml(keyword, info);
table.repaint();
}
});
JScrollPane scrollPane = new JScrollPane();
GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(22)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)
.addContainerGap())
.addGroup(groupLayout.createSequentialGroup()
.addComponent(textField, GroupLayout.DEFAULT_SIZE, 641, Short.MAX_VALUE)
.addGap(27)
.addComponent(btnNewButton)
.addGap(62))))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(5)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(btnNewButton))
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
.addContainerGap())
);
table=new JTable(info,header);
table.setRowHeight(250);
table.getColumnModel().getColumn(0).setPreferredWidth(10);
table.getColumnModel().getColumn(1).setPreferredWidth(50);
table.getColumnModel().getColumn(2).setPreferredWidth(200);
table.getColumnModel().getColumn(3).setPreferredWidth(30);
table.getColumnModel().getColumn(4).setPreferredWidth(50);
table.getColumnModel().getColumn(5).setPreferredWidth(200);
table.getColumnModel().getColumn(6).setPreferredWidth(100);
table.getColumnModel().getColumn(7).setPreferredWidth(150);
table.getColumnModel().getColumn(8).setPreferredWidth(400);
for (int i = 0; i < table.getModel().getRowCount(); i++) {
for (int j = 0; j < table.getModel().getColumnCount(); j++) {
DefaultTableCellRenderer renderer =
(DefaultTableCellRenderer)table.getCellRenderer(i, j);
renderer.setVerticalAlignment(JTextField.TOP);
} // End for(j)
} // End for(i)
scrollPane.setViewportView(table);
table.setPreferredScrollableViewportSize(new Dimension(550,30));
frame.getContentPane().setLayout(groupLayout);
}
}