目前,我特别关注:
v1.setText(value1);
v2.setText(value2);
v3.setText(value3);
v4.setText(value4);
v5.setText(value5);
v1 cannot be resolved
v2 cannot be resolved
v3 cannot be resolved
v4 cannot be resolved
v5 cannot be resolved
package Hummus;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import javax.swing.JTextArea;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
public class Dashboard extends JFrame {
/**
* @author Mohamed Gharib
* @category E-Commerce
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Dashboard frame = new Dashboard();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Dashboard() {
setUndecorated(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 700, 500);
contentPane = new JPanel();
contentPane.setBackground(Color.BLACK);
contentPane.setBorder(null);
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel navigation = new JPanel();
navigation.setBackground(new Color(40, 40, 40));
navigation.setBounds(0, 0, 700, 24);
contentPane.add(navigation);
navigation.setLayout(null);
JButton exit = new JButton("X");
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
exit.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
exit.setBackground(Color.DARK_GRAY);
}
@Override
public void mouseExited(MouseEvent e) {
exit.setBackground(new Color(40, 40, 40));
}
});
exit.setForeground(Color.GRAY);
exit.setBackground(new Color(40, 40, 40));
exit.setFont(new Font("SansSerif", Font.BOLD, 11));
exit.setFocusPainted(false);
exit.setContentAreaFilled(false);
exit.setOpaque(true);
exit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
exit.setBorder(null);
exit.setBounds(650, 0, 50, 24);
navigation.add(exit);
JButton maximize = new JButton("⬜");
maximize.setEnabled(false);
maximize.setFont(new Font("Tahoma", Font.PLAIN, 10));
maximize.setForeground(Color.GRAY);
maximize.setBackground(new Color(40, 40, 40));
maximize.setFocusPainted(false);
maximize.setContentAreaFilled(false);
maximize.setOpaque(true);
maximize.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
maximize.setBorder(null);
maximize.setBounds(600, 1, 50, 24);
navigation.add(maximize);
JButton minimize = new JButton("–");
minimize.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setExtendedState(Frame.ICONIFIED);
}
});
minimize.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
minimize.setBackground(Color.DARK_GRAY);
}
@Override
public void mouseExited(MouseEvent e) {
minimize.setBackground(new Color(40, 40, 40));
}
});
minimize.setForeground(Color.GRAY);
minimize.setBackground(new Color(40, 40, 40));
minimize.setFont(new Font("Tahoma", Font.BOLD, 11));
minimize.setFocusPainted(false);
minimize.setContentAreaFilled(false);
minimize.setOpaque(true);
minimize.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
minimize.setBorder(null);
minimize.setBounds(550, 1, 50, 24);
navigation.add(minimize);
JPanel container = new JPanel();
container.setBackground(Color.BLACK);
container.setBorder(null);
container.setBounds(44, 69, 613, 386);
contentPane.add(container);
container.setLayout(null);
JTextArea textarea = new JTextArea();
textarea.setBackground(Color.WHITE);
textarea.setFont(new Font("SansSerif", Font.PLAIN, 12));
textarea.setBounds(0, 0, 250, 284);
textarea.setBorder(null);
JScrollPane scrollPane = new JScrollPane(textarea);
scrollPane.setBounds(0, 0, 250, 284);
container.add(scrollPane);
JScrollBar scrollBar = new JScrollBar(JScrollBar.VERTICAL);
scrollBar.setBounds(277, 69, 17, 284);
scrollPane.setVerticalScrollBar(scrollBar);
JButton reset = new JButton("R E S E T");
reset.setBounds(0, 346, 250, 40);
container.add(reset);
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String textArea = textarea.getText();
if(textArea.isBlank() || textArea.isEmpty()) {
assert false;
} else {
textarea.setText("");
}
}
});
reset.setBorder(new LineBorder(Color.WHITE, 1, true));
reset.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
reset.setFocusPainted(false);
reset.setContentAreaFilled(false);
reset.setOpaque(true);
reset.setBackground(Color.BLACK);
reset.setForeground(Color.WHITE);
reset.setFont(new Font("SansSerif", Font.BOLD, 11));
JButton stop = new JButton("S T O P");
stop.setBounds(130, 295, 120, 40);
container.add(stop);
stop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
stop.setBackground(Color.BLACK);
stop.setForeground(Color.WHITE);
stop.setFont(new Font("SansSerif", Font.BOLD, 11));
stop.setFocusPainted(false);
stop.setContentAreaFilled(false);
stop.setOpaque(true);
stop.setBorder(new LineBorder(Color.WHITE, 1, true));
stop.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
JButton start = new JButton("S T A R T");
start.setBounds(0, 295, 120, 40);
container.add(start);
start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String text = textarea.getText();
String[] lines = text.split("\\r?\\n");
for (int i = 0; i < lines.length; i += 5) {
List<String> list = new ArrayList<>();
for (int j = i; j < Math.min(i + 5, lines.length); j++) {
list.add(lines[j]);
}
String value1 = (list.size() > 0) ? list.get(0) : "";
String value2 = (list.size() > 1) ? list.get(1) : "";
String value3 = (list.size() > 2) ? list.get(2) : "";
String value4 = (list.size() > 3) ? list.get(3) : "";
String value5 = (list.size() > 4) ? list.get(4) : "";
v1.setText(value1);
v2.setText(value2);
v3.setText(value3);
v4.setText(value4);
v5.setText(value5);
}
}
});
start.setBackground(Color.BLACK);
start.setForeground(Color.WHITE);
start.setFont(new Font("SansSerif", Font.BOLD, 11));
start.setBorder(new LineBorder(Color.WHITE, 1, true));
start.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
start.setFocusPainted(false);
start.setContentAreaFilled(false);
start.setOpaque(true);
JPanel table = new JPanel();
table.setBounds(263, 0, 350, 386);
container.add(table);
table.setBorder(new LineBorder(Color.GRAY, 2, true));
table.setBackground(Color.BLACK);
table.setLayout(null);
JPanel x = new JPanel();
x.setBackground(Color.GRAY);
x.setBounds(175, 0, 2, 386);
table.add(x);
JPanel xxx = new JPanel();
xxx.setBackground(Color.GRAY);
xxx.setBounds(0, 64, 350, 2);
table.add(xxx);
JPanel xxxx = new JPanel();
xxxx.setBackground(Color.GRAY);
xxxx.setBounds(0, 128, 350, 2);
table.add(xxxx);
JPanel xxxxx = new JPanel();
xxxxx.setBackground(Color.GRAY);
xxxxx.setBounds(0, 192, 350, 2);
table.add(xxxxx);
JPanel xxxxxx = new JPanel();
xxxxxx.setBackground(Color.GRAY);
xxxxxx.setBounds(0, 256, 350, 2);
table.add(xxxxxx);
JPanel xxxxxxx = new JPanel();
xxxxxxx.setBackground(Color.GRAY);
xxxxxxx.setBounds(0, 320, 350, 2);
table.add(xxxxxxx);
JLabel link = new JLabel("L I N K");
link.setFont(new Font("SansSerif", Font.BOLD, 11));
link.setForeground(Color.LIGHT_GRAY);
link.setHorizontalAlignment(SwingConstants.CENTER);
link.setBounds(0, 0, 175, 64);
table.add(link);
JLabel v1 = new JLabel("");
v1.setLabelFor(link);
v1.setFont(new Font("SansSerif", Font.BOLD, 12));
v1.setForeground(Color.LIGHT_GRAY);
v1.setHorizontalAlignment(SwingConstants.CENTER);
v1.setBounds(0, 64, 175, 64);
table.add(v1);
JLabel v2 = new JLabel("");
v2.setLabelFor(link);
v2.setFont(new Font("SansSerif", Font.BOLD, 11));
v2.setForeground(Color.LIGHT_GRAY);
v2.setHorizontalAlignment(SwingConstants.CENTER);
v2.setBounds(0, 128, 175, 64);
table.add(v2);
JLabel v3 = new JLabel("");
v3.setLabelFor(link);
v3.setForeground(Color.LIGHT_GRAY);
v3.setFont(new Font("SansSerif", Font.BOLD, 11));
v3.setHorizontalAlignment(SwingConstants.CENTER);
v3.setBounds(0, 192, 175, 64);
table.add(v3);
JLabel v4 = new JLabel("");
v4.setLabelFor(link);
v4.setFont(new Font("SansSerif", Font.BOLD, 11));
v4.setForeground(Color.LIGHT_GRAY);
v4.setHorizontalAlignment(SwingConstants.CENTER);
v4.setBounds(0, 256, 175, 64);
table.add(v4);
JLabel v5 = new JLabel("");
v5.setLabelFor(link);
v5.setFont(new Font("SansSerif", Font.BOLD, 11));
v5.setForeground(Color.LIGHT_GRAY);
v5.setHorizontalAlignment(SwingConstants.CENTER);
v5.setBounds(0, 320, 175, 64);
table.add(v5);
JLabel status = new JLabel("S T A T U S");
status.setHorizontalAlignment(SwingConstants.CENTER);
status.setForeground(Color.LIGHT_GRAY);
status.setFont(new Font("SansSerif", Font.BOLD, 11));
status.setBounds(175, 0, 175, 64);
table.add(status);
JLabel x1 = new JLabel("");
x1.setLabelFor(status);
x1.setFont(new Font("SansSerif", Font.BOLD, 11));
x1.setForeground(Color.LIGHT_GRAY);
x1.setHorizontalAlignment(SwingConstants.CENTER);
x1.setBounds(175, 64, 175, 64);
table.add(x1);
JLabel x2 = new JLabel("");
x2.setLabelFor(status);
x2.setFont(new Font("SansSerif", Font.BOLD, 11));
x2.setForeground(Color.LIGHT_GRAY);
x2.setHorizontalAlignment(SwingConstants.RIGHT);
x2.setBounds(175, 128, 175, 64);
table.add(x2);
JLabel x3 = new JLabel("");
x3.setLabelFor(status);
x3.setFont(new Font("SansSerif", Font.BOLD, 11));
x3.setForeground(Color.LIGHT_GRAY);
x3.setHorizontalAlignment(SwingConstants.CENTER);
x3.setBounds(175, 192, 175, 64);
table.add(x3);
JLabel x4 = new JLabel("");
x4.setLabelFor(status);
x4.setFont(new Font("SansSerif", Font.BOLD, 11));
x4.setForeground(Color.LIGHT_GRAY);
x4.setHorizontalAlignment(SwingConstants.CENTER);
x4.setBounds(175, 256, 175, 64);
table.add(x4);
JLabel x5 = new JLabel("");
x5.setLabelFor(status);
x5.setFont(new Font("SansSerif", Font.BOLD, 11));
x5.setForeground(Color.LIGHT_GRAY);
x5.setHorizontalAlignment(SwingConstants.CENTER);
x5.setBounds(175, 320, 175, 64);
table.add(x5);
}
}