「javadance」java单测怎么写
本篇文章给大家谈谈javadance,以及java单测怎么写对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
Java数据结构跳舞配对问题(队列的应用)
代码如下,可以直接运行。
public static void main(String[] args) {
final int M = 6; // number of girls,可改动
final int N = 7; // number of boys,可改动
int x = 3;// some boy,可改动
int y = 5;// some girl,可改动
String result = "";// 记录结果,即第二个问题
// 初始化,假设队列存放男女生编号,从1开始
QueueInteger boys = new LinkedListInteger();
for (int i = 1; i = N; i++) {
boys.add(i);
}
QueueInteger girls = new LinkedListInteger();
for (int i = 1; i = M; i++) {
girls.add(i);
}
// 跳舞开始
int min = boys.size() girls.size() ? girls.size() : boys.size();
int k = 1;// songs
int count = 2; // 求出两个值,可改动
while (k 1000) {//为了不死循环,这里假设最多有999支舞蹈
System.out.println("***This is the " + k + "st dance:");
for (int i = 0; i min; i++) {
// 跳舞,第一个问题:输出每曲配对情况
System.out.println("Boy " + boys.peek() + " = Girl "
+ girls.peek());
// 跳过的排到对尾
int boy = boys.remove();
boys.add(boy);
int girl = girls.remove();
girls.add(girl);
// 判断 x和y跳舞了没有
if (boy == x girl == y) {
result += k + ",";
count--;
}
}
if (count == 0)
break;
// next dance
k++;
}
// 结果
if (count == 0)
System.out.println("\n***Boy " + x + " and Girl " + y
+ " dance together in : " + result);//第二个问题的解答,跳了哪几支舞
else
System.out.println("\n***Boy " + x + " and Girl " + y
+ " have no chance to dance!");//第二个问题的解答,两人没机会跳舞
}
java web开发部 有两个下拉框,我要做的是在选完第一个下拉框时,第二个下拉框才可选,代码该怎样写
第一个下拉框绑定一个onchange事件,第二个下拉框保持为没有选项,当选中第一个下框某项时在动态获取第二个下拉框的内容
一道Java的编程题~~!!
regedit;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
public class Regedit extends JFrame {
private JLabel account = new JLabel("账号");
private JTextField aText = new JTextField(10);
private JLabel password = new JLabel("密码");
private JPasswordField pText = new JPasswordField(10);
private JLabel conpass = new JLabel("确认密码");
private JPasswordField cText = new JPasswordField(10);
private JLabel birthday = new JLabel(" 生日");
private JComboBox year = new JComboBox(data(11, 1985));
private JLabel y = new JLabel("年");
private JComboBox month = new JComboBox(data(13, 0));
private JLabel m = new JLabel("月");
private JComboBox day = new JComboBox(data(32, 0));
private JLabel d = new JLabel("日");
private JLabel sex = new JLabel("性别");
private ButtonGroup group = new ButtonGroup();
private JRadioButton man = new JRadioButton("男", false);
private JRadioButton woman = new JRadioButton("女", false);
private JLabel interest = new JLabel(" 兴趣");
private JCheckBox read = new JCheckBox("阅读");
private JCheckBox sing = new JCheckBox("唱歌");
private JCheckBox dance = new JCheckBox("跳舞");
private JLabel remakes = new JLabel(" 备注");
private JTextArea rText = new JTextArea(6, 15);
private JButton button = new JButton("注册");
private String name, pass1, pass2, birth = "", intre = "", se, remake;
public static void main(String[] args) {
new Regedit();
}
public Regedit() {
setTitle("Regedit");
JPanel tz = new JPanel(new GridLayout(1, 2));
JPanel tOne = new JPanel(new GridLayout(3, 2));
JPanel tTwo = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel tThree = new JPanel(new BorderLayout());
JPanel tFour = new JPanel(new BorderLayout());
JPanel tFive = new JPanel(new GridLayout(3, 1));
JPanel tSix = new JPanel(new GridLayout(1, 2));
JPanel tSeven = new JPanel(new GridLayout(2, 1));
JPanel tEight = new JPanel(new GridLayout(2, 1));
JPanel tNine = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel tTen = new JPanel(new GridLayout(1, 2));
setLayout(new GridLayout(1, 2));
tOne.add(account);
tOne.add(aText);
aText.addActionListener(new Textaction(aText));
tOne.add(password);
tOne.add(pText);
pText.addActionListener(new Textaction(pText));
pText.setEchoChar('*');
tOne.add(conpass);
tOne.add(cText);
cText.addActionListener(new Textaction(cText));
cText.setEchoChar('*');
tTwo.add(birthday);
tTwo.add(year);
year.addActionListener(new birthday(year));
tTwo.add(y);
tTwo.add(month);
month.addActionListener(new birthday(month));
tTwo.add(m);
tTwo.add(day);
day.addActionListener(new birthday(day));
tTwo.add(d);
tSix.add(sex);
group.add(man);
man.addActionListener(new sex());
group.add(woman);
woman.addActionListener(new sex());
tSeven.add(man);
tSeven.add(woman);
tSeven.setBorder(BorderFactory.createLineBorder(Color.gray));
tSix.add(tSeven);
tFour.add(interest, BorderLayout.WEST);
tFive.add(read);
read.addActionListener(new interest(read));
tFive.add(sing);
sing.addActionListener(new interest(sing));
tFive.add(dance);
dance.addActionListener(new interest(dance));
tFive.setBorder(BorderFactory.createLineBorder(Color.gray));
tFour.add(tFive);
tNine.add(remakes);
rText.setBorder(BorderFactory.createLineBorder(Color.gray));
tNine.add(rText);
rText.setLineWrap(true);
tNine.add(button);
button.addActionListener(new button());
tz.add(tOne);
tThree.add(tTwo, BorderLayout.NORTH);
tThree.add(tFour);
tz.add(tThree);
tEight.add(tz);
tTen.add(tSix);
tTen.add(tNine);
tEight.add(tTen);
add(tEight);
pack();
setVisible(true);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private Integer[] data(int day, int j) {
Integer[] data = new Integer[day];
data[0] = null;
if (j == 0)
j = 1;
for (int i = 1; i data.length; i++) {
data[i] = j + i - 1;
}
return data;
}
class Textaction implements ActionListener {
private JTextField text;
public Textaction(JTextField JTF) {
text = JTF;
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == aText) {
name = text.getText();
FocusManager.getCurrentManager().focusNextComponent();
}
if (e.getSource() == pText) {
FocusManager.getCurrentManager().focusNextComponent();
pass1 = text.getText();
}
if (e.getSource() == cText) {
pass2 = text.getText();
FocusManager.getCurrentManager().focusNextComponent();
}
}
}
class birthday implements ActionListener {
private JComboBox combo = new JComboBox();
public birthday(JComboBox JCB) {
combo = JCB;
}
public void actionPerformed(ActionEvent e) {
birth += combo.getSelectedItem() + " ";
}
}
class sex implements ActionListener {
public void actionPerformed(ActionEvent e) {
se = e.getActionCommand();
}
}
class interest implements ActionListener {
private JCheckBox check;
public interest(JCheckBox JBC) {
check = JBC;
}
public void actionPerformed(ActionEvent e) {
if (check.isSelected()) {
intre += e.getActionCommand() + " ";
}
}
}
class button implements ActionListener {
public void actionPerformed(ActionEvent e) {
int result = JOptionPane.showConfirmDialog(null, "您确定注册吗?", "请确认",
JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.OK_OPTION) {
remake = remakes.getText();
try {
FileWriter out = new FileWriter("D:/Information.txt", true);
out.write(name + " " + pass1 + " " + se + " " + birth + " "
+ intre + " " + remake + "\r\n");
out.close();
} catch (IOException io) {
io.getStackTrace();
}
}
}
}
}
关于javadance和java单测怎么写的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-11-22,除非注明,否则均为
原创文章,转载请注明出处。