-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixGUI.java
More file actions
97 lines (78 loc) · 3.06 KB
/
Copy pathMatrixGUI.java
File metadata and controls
97 lines (78 loc) · 3.06 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
95
96
97
package ui;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionListener;
public class MatrixGUI extends JFrame {
private JComboBox<String> sizeBox;
private JTextField thresholdField;
private DefaultTableModel tableModel;
private JButton runButton;
private JButton clearButton;
public MatrixGUI() {
setTitle("model.Matrix Multiplication Benchmark");
setSize(750, 450);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout(10, 10));
setLocationRelativeTo(null);
addControls();
addResultsTable();
}
private void addControls() {
JPanel top = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 10));
sizeBox = new JComboBox<>(new String[]{"128", "256", "512", "1024"});
thresholdField = new JTextField("64", 6);
runButton = new JButton("Run Test");
clearButton = new JButton("Clear Results");
top.add(new JLabel("Matrix Size:"));
top.add(sizeBox);
top.add(new JLabel("Threshold:"));
top.add(thresholdField);
top.add(runButton);
top.add(clearButton);
add(top, BorderLayout.NORTH);
}
private void addResultsTable() {
String[] columns = {"Matrix Size", "Threshold", "Sequential (ms)", "Parallel (ms)", "Speedup"};
tableModel = new DefaultTableModel(columns, 0);
JTable resultsTable = new JTable(tableModel);
resultsTable.setFont(new Font("Monospaced", Font.PLAIN, 12));
resultsTable.setRowHeight(25);
add(new JScrollPane(resultsTable), BorderLayout.CENTER);
}
public void addRunListener(ActionListener listener) {
runButton.addActionListener(listener);
}
public void addClearListener(ActionListener listener) {
clearButton.addActionListener(listener);
}
public int getSelectedSize() {
return Integer.parseInt((String) sizeBox.getSelectedItem());
}
public int getThreshold() throws NumberFormatException {
return Integer.parseInt(thresholdField.getText());
}
public void setControlsEnabled(boolean enabled) {
sizeBox.setEnabled(enabled);
thresholdField.setEnabled(enabled);
runButton.setEnabled(enabled);
}
public void clearTable() {
tableModel.setRowCount(0);
}
public int addInitialRow(String size, int threshold, long seqTime) {
tableModel.addRow(new Object[]{size, threshold, seqTime, "-", "-"});
return tableModel.getRowCount() - 1;
}
public void updateParallelResults(int rowIndex, long parTime, String speedup) {
tableModel.setValueAt(parTime, rowIndex, 3);
tableModel.setValueAt(speedup, rowIndex, 4);
}
// Updates just the time (useful for live updates if needed)
public void updateParallelTime(int rowIndex, long time) {
tableModel.setValueAt(time, rowIndex, 3);
}
public void showError(String message) {
JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
}
}