Compare commits

...

11 Commits

Author SHA1 Message Date
msksbr 4617a873f2 这都是什么玩意 2025-05-03 18:13:17 +08:00
msksbr 95e3fdb53d 哈哈哈哈哈,检查进制来咯 2024-09-26 21:35:39 +08:00
msksbr e6b23db7ff 来做计ç®挑æˆ题了 2024-09-26 21:14:44 +08:00
msksbr 1f5b1b36d5 不装逼了😭 2024-07-10 12:08:25 +08:00
msksbr 83d47288a5 飞起来 2024-07-10 12:02:38 +08:00
msksbr 0bfd51ce5a 阿米诺斯 2024-07-10 11:48:29 +08:00
msksbr acf7e3f95a 冒泡 2024-06-23 23:48:00 +08:00
msksbr 10fcbc02e5 太棒了,我逐渐理解一切 2024-06-23 21:43:04 +08:00
msksbr c179256b80 把计算器完善完了 2024-06-22 21:56:32 +08:00
msksbr 44fe8b49ed 做了个计算器 2024-06-22 01:42:41 +08:00
msksbr 3a1a7a2005 加了点好van♂的东西 2024-06-21 22:34:39 +08:00
41 changed files with 630 additions and 1 deletions
+3
View File
@@ -29,3 +29,6 @@ hs_err_pid*
#test.java
test/test.java
#jdk-1.8
test/Click-Shutdown/jdk-1.8/
Binary file not shown.

After

Width:  |  Height:  |  Size: 594 KiB

+8
View File
@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
@@ -0,0 +1,10 @@
<component name="ArtifactManager">
<artifact name="Click-Shutdown:jar">
<output-path>$PROJECT_DIR$/out/artifacts/Click_Shutdown_jar</output-path>
<root id="root">
<element id="archive" name="Click-Shutdown.jar">
<element id="module-output" name="Click-Shutdown" />
</element>
</root>
</artifact>
</component>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Click-Shutdown.iml" filepath="$PROJECT_DIR$/Click-Shutdown.iml" />
</modules>
</component>
</project>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
+7
View File
@@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+18
View File
@@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
@@ -0,0 +1 @@
Main-Class: com.msksbr.click_2_shutdown.Main
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.msksbr.click_2_shutdown.Main
@@ -0,0 +1 @@
Main-Class: com.msksbr.click_2_shutdown.Main
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.msksbr.click_2_shutdown.Main
@@ -0,0 +1,47 @@
package com.msksbr.click_2_shutdown;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
Frame frame = new Frame("关机?");
frame.setBounds(200, 200, 250, 250);
frame.setVisible(true);
frame.setLayout(new FlowLayout());
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
try {
Runtime.getRuntime().exec("shutdown -s -t 00");
Runtime.getRuntime().exec("poweroff");
Runtime.getRuntime().exec("shutdown -h now");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
Button button = new Button("OK");
frame.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
Runtime.getRuntime().exec("shutdown -s -t 00");
Runtime.getRuntime().exec("poweroff");
Runtime.getRuntime().exec("shutdown -h now");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
}
@@ -0,0 +1 @@
Main-Class: com.msksbr.click_2_shutdown.Main
+8
View File
@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="23" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/GUItest.iml" filepath="$PROJECT_DIR$/GUItest.iml" />
</modules>
</component>
</project>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
+2 -1
View File
@@ -3,5 +3,6 @@
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
],
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable"
}
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+7
View File
@@ -0,0 +1,7 @@
package Calculator;
public class Main {
public static void main(String[] args) {
new MyFrame();
}
}
+105
View File
@@ -0,0 +1,105 @@
package Calculator;
import java.awt.Button;
import java.awt.Dialog;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class MyFrame extends Frame {
public MyFrame() {
super("Calculator");
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
});
setVisible(true);
setBounds(400, 400, 300, 200);
TextField num1 = new TextField();
Label addKey = new Label("+");
TextField num2 = new TextField();
Button equal2 = new Button("=");
TextField goal = new TextField();
setLayout(new FlowLayout());
setResizable(false);
add(num1);
add(addKey);
add(num2);
add(equal2);
add(goal);
equal2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
goal.setText(add(Double.valueOf(num1.getText()), Double.valueOf(num2.getText())));
try {
goal.setText(add(Integer.valueOf(num1.getText()), Integer.valueOf(num2.getText())));
} catch (java.lang.NumberFormatException event) {
// TODO: handle exception
}
} catch (java.lang.NumberFormatException event) {
// TODO: handle exception
CreateWarning(num1, num2, goal);
}
}
});
}
public void CreateWarning(TextField num1, TextField num2, TextField goal) {
Dialog warning = new Dialog(this, "warning!");
warning.setLayout(new GridLayout(2, 1));
warning.setSize(400, 200);
warning.setVisible(true);
warning.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
warning.dispose();
num1.setText("");
num2.setText("");
goal.setText("");
}
});
Panel Message = new Panel(new FlowLayout());
Panel CloseButton = new Panel(new FlowLayout());
Button closeButton = new Button("close");
Label message = new Label("please enter a valid number!");
closeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
warning.dispose();
num1.setText("");
num2.setText("");
goal.setText("");
}
});
Message.add(message);
CloseButton.add(closeButton);
warning.add(Message);
warning.add(CloseButton);
}
public String add(double num1, double num2) {
return String.valueOf(num1 + num2);
}
public String add(int num1, int num2) {
return String.valueOf(num1 + num2);
}
}
@@ -0,0 +1,26 @@
package loginWindow;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class CenterPanel extends Panel {
public CenterPanel() {
setLayout(new GridLayout(3, 1));
TextField UserName = new TextField();
TextField Password = new TextField();
Button commit = new Button("commit");
Password.setEchoChar('*');
add(UserName);
add(Password);
add(commit);
commit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("Username: \t" + UserName.getText());
System.out.println("Password: \t" + Password.getText());
}
});
}
}
+7
View File
@@ -0,0 +1,7 @@
package loginWindow;
public class Main {
public static void main(String[] args) {
new MyFrame();
}
}
+23
View File
@@ -0,0 +1,23 @@
package loginWindow;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class MyFrame extends Frame {
public MyFrame() {
setVisible(true);
setBounds(200, 200, 680, 400);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
});
setLayout(new BorderLayout());
add(new SidePanel((int)(getWidth()*0.2),getHeight()), BorderLayout.WEST);
add(new CenterPanel(), BorderLayout.CENTER);
add(new SidePanel((int)(getWidth()*0.2),getHeight()), BorderLayout.EAST);
}
}
@@ -0,0 +1,10 @@
package loginWindow;
import java.awt.*;
public class SidePanel extends Panel {
public SidePanel(int width, int height) {
setBackground(new Color(0X39, 0XC5, 0XBB));
setSize(width, height);
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
+18
View File
@@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
+33
View File
@@ -0,0 +1,33 @@
import java.sql.*;
import java.util.Scanner;
import javax.sql.*;
import com.mysql.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/game", "root", sc.next());
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM player;");
while (resultSet.next()) {
System.out.println("id:\t" + resultSet.getInt("id"));
System.out.println("name:\t" + resultSet.getString("name"));
System.out.println("sex:\t" + resultSet.getString("sex"));
System.out.println("email:\t" + resultSet.getString("email"));
System.out.println("level:\t" + resultSet.getInt("level"));
System.out.println("exp:\t" + resultSet.getInt("exp"));
System.out.println("gold:\t" + resultSet.getDouble("gold"));
System.out.println("------------------------------------------------");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
+13
View File
@@ -0,0 +1,13 @@
<p>
<font face="仿宋">
比较两个相同进制(2进制~16进制)的数值大小。从键盘上输入两个正确(数码符合当前进制)的相同进制的数值字符串(不带正负号,可以有小数点),比较大小,输出“大于”、“小于”或者“等于”。注意:设计的算法与具体的进制无关。
</font>
</p>
<p><br /></p>
<p>输入说明:在两行分别输入一个数值字符串</p>
<p><br /></p>
<p>输出说明:比较结果</p>
<p><br /></p>
<p>输入样例1123 <br /> 1234<br />输入样例212345<br /> abcd</p>
<p><br /></p>
<p>输出样例1:小于<br />输出样例2:大于</p>
+29
View File
@@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
+8
View File
@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/nuccu.iml" filepath="$PROJECT_DIR$/nuccu.iml" />
</modules>
</component>
</project>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+47
View File
@@ -0,0 +1,47 @@
package y22.q16;
/* HashSet是Java中常用的Set集合,向HashSet集合中添加数据对象时,首先会调用对象的hashCode()方法获取哈希码,根据哈希码计算对象的存储位置,如果相应位置上已经有数据对象,则会调用对象的equals()方法判断新加入的对象与现有对象是否重复,如果重复则拒绝加入。为了使用HashSet集合正确存储自定义类的对象,自定义类需要重写equals()方法和hashCode()方法。
* 编写程序完成以下功能:定义一个学生类Student,属性包括String类型的id、name和int类型的age(id属性字符串内容相同的则认为是同一个学生),为三个属性定义get和set方法。重写equals()方法和hashCode()方法,使得当使用HashSet存储Student类的对象时,id重复的学生对象不能重复添加到集合。输入4个学生类对象的属性值,创建4个Student类对象,将其添加到一个HashSet<Student>集合,遍历集合,输出集合中各个学生的信息。
* 输入说明:输入4个Student类对象的属性值,每个对象属性值按一行输入,以空格分割。
* 输出说明:集合中存储的Student类对象的信息,每个对象信息占一行,输出格式为 id:name:age。
* 输入样例1
* 2022001 Tom 19
* 2022002 Jerry 18
* 2022003 Eason 20
* 2022002 Jerry 18
* 输入样例2
* 2022001 Tom 19
* 2022002 Jerry 18
* 2022003 Eason 20
* 2022004 Jerry 18
* 输出样例1
* 2022001:Tom:19岁
* 2022002:Jerry:18岁
* 2022003:Eason:20岁
* 输出样例2
* 2022001:Tom:19岁
* 2022002:Jerry:18岁
* 2022003:Eason:20岁
* 2022004:Jerry:18岁*/
import java.util.HashSet;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Student[] students = new Student[4];
HashSet<Student>[] StudentSet;
for (int i = 0; i < students.length; i++) {
students[i] = new Student();
students[i].setId(sc.next());
students[i].setName(sc.next());
students[i].setAge(sc.nextInt());
}
StudentSet = students;
for (int i = 0; i < StudentSet.length; i++) {
System.out.println(StudentSet[i].toString());
}
}
}
+52
View File
@@ -0,0 +1,52 @@
package y22.q16;
import java.util.HashSet;
import java.util.Objects;
public class Student extends HashSet {
private String id;
private String name;
private int age;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if(o==null||getClass()!=o.getClass()) return false;
Student student = (Student) o;
return Objects.equals(id,student.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return this.id+":"+this.name+":"+this.age;
}
}
+40
View File
@@ -0,0 +1,40 @@
package y22.q17;
/*
* 比较两个相同进制(2进制~16进制)的数值大小。从键盘上输入两个正确(数码符合当前进制)的相同进制的数值字符串(不带正负号,可以有小数点),比较大小,输出“大于”、“小于”或者“等于”。注意:设计的算法与具体的进制无关。
* 输入说明:在两行分别输入一个数值字符串
* 输出说明:比较结果
* 输入样例1123
* 1234
* 输入样例212345
* abcd
* 输出样例1:小于
* 输出样例2:大于
* */
import java.util.Scanner;
public class Main {
public static int getScale(String input) {
int scale = 0;
for (int i = 0; i < input.length(); i++) {
Integer j;
try {
j = Integer.valueOf(input.substring(i));
} catch (NumberFormatException e) {
j = 0;
}
if (j > scale) {
scale = j;
}
}
return scale;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String input1 = sc.next();
String input2 = sc.next();
}
}