在eclipse上写java代码,用ctrl+z返回上一步了就点不了重做按钮了。。。每次都不吸取教训,下意识地ctrl+z,还经常撤回过头。。。。
感谢我的舍友帮我解决了之前的问题,虽然过程极其曲折,曲折到我们同时怀疑自己是否配得上这份文凭
命令提示符,就是那个cmd,有的程序在里面能运行却不能在eclipse上运行,极有可能是你少了开头的package
为啥我大二下才能用java呀,之前的作业都是用c语言,指针特别难弄,欸……
先分享一些我觉得对写这个小项目很有用的、可以单独编译的代码,有一些是网上找的,但是一堆bug,我给修好了
首先是昨天的问题的解答——
package Mini;
import java.awt.List.*;
import java.util.ArrayList;
public class Test2 {
public static void main(String[] args) {
// 创建并初始化 List
ArrayList list = new ArrayList();
list.add(new Person1(1, 30, "北京"));
list.add(new Person1(2, 20, "西安"));
list.add(new Person1(3, 40, "上海"));
// 打印 list 集合
for(int i=0;i
然后是变换label中字体的方法——
package Mini;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Test3 {
public Test3() {
//字体样式设置方法1
JFrame f = new JFrame("Wordle Game");
f.setLayout(new FlowLayout( FlowLayout.CENTER));
f.setSize(400,250);
f.setLocation(400,300);
JLabel jl1 = new JLabel("床前明月光");
Font font = new Font("宋体", Font.PLAIN, 25);
jl1.setFont(font);
jl1.setForeground(new Color(0,245,255));
//字体样式设置方法2
JLabel jl2 = new JLabel("疑是地上霜");
f.add(jl1);
f.add(jl2);
f.setTitle("字体设置");//标题
f.setSize(500,300);//窗口大小
f.setLocationRelativeTo(null);//窗口居中
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Test3();//创建窗口实例
}
}
最后是弹出窗体实验——
package Mini;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Test4 {
public Test4(){
final JFrame jf=new JFrame("弹出窗体实验");
Dimension screensize=Toolkit.getDefaultToolkit().getScreenSize();
int Swing1x=500;
int Swing1y=300;
jf.setBounds(screensize.width/2-Swing1x/2,screensize.height/2-Swing1y/2,Swing1x,Swing1y);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c=jf.getContentPane();
c.setBackground(Color.red);
c.setLayout(null);
Dimension Swing1size=jf.getSize();
JButton jb=new JButton("弹出对话窗");
int jbx=100;
int jby=30;
jb.setBounds(Swing1size.width/2-jbx/2,Swing1size.height/2-jby/2,jbx,jby);
c.add(jb);
class Dialog1 {
JDialog jd=new JDialog(jf,"JDialog窗体",true);
Dialog1(){
jd.setSize(300,200);
Container c2=jd.getContentPane();
c2.setLayout(null);
JLabel jl=new JLabel("只是一个对话框");
jl.setBounds(0,20,100,100);
JButton jbb=new JButton("确定");
jbb.setBounds(100,100,60,30);
c2.add(jl);
c2.add(jbb);
jbb.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
jd.dispose();
}
});
System.out.println("点击弹出");
jd.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
}
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new Dialog1().jd.setVisible(true);//弹出对话框
System.out.println("弹出对话框");
}
});
System.out.println("初始");
}
public static void main(String[] args){
new Test4();
}
}
最后附上今天完成的代码,已经完成字母颜色配对这一大难关啦!(特别长的代码,还没简化,大概400行)
package Mini;
import javax.swing.*;
import java.awt.List.*;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.*;
import java.awt.Color;
import java.awt.Font;
//import java.util.stream.Collectors;
class oneword {
private int charterr;//0是用户输入,1是设定的单词,定好了后续不会改
private int wordnumber;//被猜单词是表中的第几个,从1开始,用户输入的单词默认为0,需要SET GET
private int timess;//第几次输入,从1开始,是设定的单词默认为9,需要SET GET
private int bgcolor;//背景色,0灰1黄2绿,是设定的单词默认为9,需要SET GET
private int seatt;//位置,从1开始,需要SET GET
private char contentt;//内容,需要GET
public oneword(int charterr, int wordnumber,int timess,int bgcolor,int seatt, char contentt) {
this.charterr = charterr;
this.wordnumber = wordnumber;
this.timess = timess;
this.bgcolor = bgcolor;
this.seatt = seatt;
this.contentt = contentt;
}
public void setWordnumber(int wordnumber) {
this.wordnumber=wordnumber;
}
public int getWordnumber() {
return wordnumber;
}
public void setTimess(int timess) {
this.timess=timess;
}
public int getTimess() {
return timess;
}
public void setBgcolor(int bgcolor) {
this.bgcolor=bgcolor;
}
public int getBgcolor() {
return bgcolor;
}
public void setSeatt(int seatt) {
this.seatt=seatt;
}
public int getSeatt() {
return seatt;
}
public char getContentt() {
return contentt;
}
public String toString() {
return charterr+" "+wordnumber+" "+timess+" "+bgcolor+" "+seatt+" "+contentt;//测试返回值
}
}
public class Test {
static int wordnumber=0;//暂时没用
static int tss=0;//第几次输入
static ArrayList list = new ArrayList();
static ArrayList putin = new ArrayList();
public static void main(String[] args) {
// index0();
index1();//测试一下假如设定好了GAMER
addwords();
putin.add(new oneword(0,0,1,1,1,'A'));//由于putin最开始是空的,难以测试
}
public static void addwords() {
list.add(new oneword(1,1,9,9,1,'G'));
list.add(new oneword(1,1,9,9,2,'A'));
list.add(new oneword(1,1,9,9,3,'M'));
list.add(new oneword(1,1,9,9,4,'E'));
list.add(new oneword(1,1,9,9,5,'R'));
for(int i=0;i'Z') {
judge=0;
}
// System.out.print("'" + c + "',");
}
if(judge==0) {
JFrame ff1 = new JFrame(" ");
JDialog nochoose = new JDialog(ff1,"Hint");//没能输入正确的五个大写字母,弹出提示
nochoose.setBounds(500,400,400,100);
nochoose.setLayout(new FlowLayout( FlowLayout.CENTER));
Box vBox0 = Box.createVerticalBox();
vBox0.add(new Label("Failure to enter the correct five capital letters."));
nochoose.add(vBox0);
nochoose.setVisible(true);
nochoose.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}else if(judge==1) {
tss=tss+1;//输入的次数
matching(str,tss);//判断输入内容并给予输入的次数
}
System.out.println();
}
public static void matching(String str,int tss) {//后续改成返回int的函数?
int ct=0;//ct是输入字母的位置
for (char c : str.toCharArray()) {//每个字母都matching一遍
ct=ct+1;//字母位置从1开始
int[] hh= {0,0,0,0,0};//带着位置和内容的c分别与gamer对比,只内容一样就是黄1,内容和位置一样就是绿2,取最大值
int ccolor=0;
for(int i=0;i



