设计一个java程序,实现gui界面和数组的操作!
设计一个java程序,实现gui界面和数组的操作!设计一个gui界面,界面菜单有添加和删除还有查找按钮,界面上有一个文本框,在文本框中输入内容后按添加按钮就可将信息添加到...
设计一个java程序,实现gui界面和数组的操作!设计一个gui界面,界面菜单有添加和删除还有查找按钮,界面上有一个文本框,在文本框中输入内容后按添加按钮就可将信息添加到一个数组中。同理实现删除和查找功能。 求java大神解答。
展开
展开全部
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class SortRandomNumber extends JPanel {
private int[] numbers = new int[33];
private Random r = new Random();
public SortRandomNumber() {
setPreferredSize(new Dimension(400, 100));
setBackground(new Color(249, 249, 0));
final JButton[] buttons = { new JButton("0"), new JButton("0"),
new JButton("0"), new JButton("0"), new JButton("0"),
new JButton("0"), new JButton("0") };
JPanel btnPanel = new JPanel();
btnPanel.setOpaque(false);
setLayout(new BorderLayout());
add(btnPanel, BorderLayout.NORTH);
for (JButton b : buttons) {
b.setBackground(new Color(205, 151, 249));
b.setFocusPainted(false);
btnPanel.add(b);
}
JPanel opPanel = new JPanel();
opPanel.setOpaque(false);
add(opPanel, BorderLayout.SOUTH);
final JButton[] opButtons = { new JButton("创建数字"), new JButton("排序"),
new JButton("重置") };
for (JButton b : opButtons) {
b.setBackground(new Color(152, 205, 249));
b.setFocusPainted(false);
b.setFont(new Font("微软雅黑", Font.PLAIN, 16));
opPanel.add(b);
}
opButtons[0].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SwingWorker<int[], Object> worker = new SwingWorker<int[], Object>() {
@Override
protected int[] doInBackground() throws Exception {
Arrays.fill(numbers, 0);
for (int i = 0; i < numbers.length; i++) {
int temp = r.nextInt(33);
if (numbers[temp] != 0) {
i--;
continue;
}
numbers[temp] = i + 1;
}
return numbers;
}
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class SortRandomNumber extends JPanel {
private int[] numbers = new int[33];
private Random r = new Random();
public SortRandomNumber() {
setPreferredSize(new Dimension(400, 100));
setBackground(new Color(249, 249, 0));
final JButton[] buttons = { new JButton("0"), new JButton("0"),
new JButton("0"), new JButton("0"), new JButton("0"),
new JButton("0"), new JButton("0") };
JPanel btnPanel = new JPanel();
btnPanel.setOpaque(false);
setLayout(new BorderLayout());
add(btnPanel, BorderLayout.NORTH);
for (JButton b : buttons) {
b.setBackground(new Color(205, 151, 249));
b.setFocusPainted(false);
btnPanel.add(b);
}
JPanel opPanel = new JPanel();
opPanel.setOpaque(false);
add(opPanel, BorderLayout.SOUTH);
final JButton[] opButtons = { new JButton("创建数字"), new JButton("排序"),
new JButton("重置") };
for (JButton b : opButtons) {
b.setBackground(new Color(152, 205, 249));
b.setFocusPainted(false);
b.setFont(new Font("微软雅黑", Font.PLAIN, 16));
opPanel.add(b);
}
opButtons[0].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SwingWorker<int[], Object> worker = new SwingWorker<int[], Object>() {
@Override
protected int[] doInBackground() throws Exception {
Arrays.fill(numbers, 0);
for (int i = 0; i < numbers.length; i++) {
int temp = r.nextInt(33);
if (numbers[temp] != 0) {
i--;
continue;
}
numbers[temp] = i + 1;
}
return numbers;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询