
正文
java简单课题代码 java毕业设计
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
大一java课题代码,要求:复制粘贴后就能用的,1000行以上,可追加分数,看你的是不是没重复的,下载的不
import java.awt.Container;
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.event.*;
class S extends JFrame implements ActionListener {
int w = this.getToolkit().getScreenSize().width;// 屏幕宽
int h = this.getToolkit().getScreenSize().height;// 屏幕高
JButton send = new JButton("发送消息");// 发送消息按钮
JTextArea ta = new JTextArea();// 记录
JScrollPane content = new JScrollPane(ta);// 装记录的scroll
String ip = null;
int port = 10000;
String name = "6035";
S() {
this.setTitle("发送消息");
this.setSize(400, 400);
this.setVisible(true);
this.setLocation((w - 400) / 2, (h - 300) / 2);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = this.getContentPane();
c.setLayout(null);
this.add(send);
send.addActionListener(this);
send.setActionCommand("send");// 添加监听命令
send.setSize(120, 30);
send.setLocation(0, 300);
this.add(content);
content.setSize(400, 300);// 大小
content.setLocation(0, 0);// 位置
}
public void actionPerformed(ActionEvent a) {
String str = a.getActionCommand();
Socket s;
PrintStream ps;
System.out.println(str);
if (str.equals("send")) {
String ss = this.ta.getText();
if (ss != null !ss.equals("")) {
try {
InetAddress addr = InetAddress.getLocalHost();
ip = addr.getHostAddress().toString();
String address = addr.getHostName().toString();
} catch (Exception e) {
System.out.println(e);
}
try {
s = new Socket(ip, port);
ps = new PrintStream(s.getOutputStream(), true);
ps.println(name + "" + ss);
ps.close();
s.close();
} catch (Exception e) {
} finally {
this.ta.setText("");
JOptionPane.showMessageDialog(this, "发送成功");
System.gc();
}
} else {
JOptionPane.showMessageDialog(this, "java简单课题代码你好像没有输入消息内容");
}
}
}
public static void main(String[] args) {
new S();
}
}
class Sa extends JFrame implements ActionListener {
int w = this.getToolkit().getScreenSize().width;// 屏幕宽
int h = this.getToolkit().getScreenSize().height;// 屏幕高
JButton send = new JButton("发送消息");// 发送消息按钮
JTextArea ta = new JTextArea();// 记录
JScrollPane content = new JScrollPane(ta);// 装记录的scroll
String ip = null;
int port = 10000;
String name = "5306";
Sa() {
this.setTitle("发送消息");
this.setSize(400, 400);
this.setVisible(true);
this.setLocation((w - 400) / 2, (h - 300) / 2);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = this.getContentPane();
c.setLayout(null);
this.add(send);
send.addActionListener(this);
send.setActionCommand("send");// 添加监听命令
send.setSize(120, 30);
send.setLocation(0, 300);
this.add(content);
content.setSize(400, 300);// 大小
content.setLocation(0, 0);// 位置
}
public void actionPerformed(ActionEvent a) {
String str = a.getActionCommand();
Socket s;
PrintStream ps;
System.out.println(str);
if (str.equals("send")) {
String ss = this.ta.getText();
if (ss != null !ss.equals("")) {
try {
InetAddress addr = InetAddress.getLocalHost();
ip = addr.getHostAddress().toString();
String address = addr.getHostName().toString();
} catch (Exception e) {
System.out.println(e);
}
try {
s = new Socket(ip, port);
ps = new PrintStream(s.getOutputStream(), true);
ps.println(name + "" + ss);
ps.close();
s.close();
} catch (Exception e) {
} finally {
this.ta.setText("");
JOptionPane.showMessageDialog(this, "发送成功");
System.gc();
}
} else {
JOptionPane.showMessageDialog(this, "你好像没有输入消息内容");
}
}
}
public static void main(String[] args) {
new Sa();
}
}
public class Meeting extends JFrame implements ActionListener, Runnable {
int w = this.getToolkit().getScreenSize().width;// 屏幕宽
int h = this.getToolkit().getScreenSize().height;// 屏幕高
ServerSocket ss = null;
int port = 10000;// 定义端口
String strlist[] = new String[5];// 装到list组件里
int strlists = 0;// 定义strlist的位置
String name = "这名真乖";// 用记名子java简单课题代码,可以更改
JList list = new JList();// 定义下接菜单装IP用
JScrollPane jp = new JScrollPane(list);// 装下拉菜用
JButton b1 = new JButton("添加-ip");// 按钮添加IP用==ActionListener==ip
JButton ipm = new JButton("修改-ip");// 按钮添加IP用==ActionListener==ip
JButton b2 = new JButton("发送消息");// 按钮发送消息用==ActionListener==message
JButton b3 = new JButton("更改名子");// 按钮发送换名子用==ActionListener==name
JButton help = new JButton("使用帮助");
JButton broadcast = new JButton("群发消息");
JButton del = new JButton("删除-ip");// 删除IP
JLabel j = new JLabel("请大家正确使用,如果出现连接时间过长,有可能是IP错误,请大家等一会就好了");
JTextArea ta = new JTextArea();// 聊天记录
JScrollPane jpta = new JScrollPane(ta);// 装聊天记录的scroll
Socket socket = null;
String ip = null;
String ipaddres ;
Meeting() {
// jframe设计
this.setTitle("--会话");
this.setSize(500, 600);
this.setVisible(true);
this.setLocation((w - 600) / 2, (h - 600) / 2);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 使用null布局
Container c = this.getContentPane();
c.setLayout(null);
fun();// 添加组件方法
try {
ss = new ServerSocket(10000);
System.out.println("开始监听10000");
while (true) {
socket = ss.accept();
System.out.println("有人连接10000");
new Thread(this).start();
System.gc();
}
} catch (Exception e) {
}
}
public void fun() {
// 添加组件scroll--JList
try {
InetAddress addr = InetAddress.getLocalHost();
ip = addr.getHostAddress().toString();
} catch (Exception e) {
}
strlist[strlists++] = ip;
list.setListData(strlist);
this.add(jp);
ta.setEditable(false);
jp.setSize(150, 70);
jp.setLocation(340, 450);
// 添加组件b1添加IP==========添加IP 修改ip
this.add(b1);
this.add(ipm);
ipm.setSize(100, 20);
ipm.setLocation(340, 450 + 70 + 25);
ipm.addActionListener(this);
ipm.setActionCommand("ipm");
b1.setSize(100, 20);
b1.setLocation(340, 450 + 70);
b1.addActionListener(this);// 添加监听
b1.setActionCommand("ip");// 添加监听命令
// 添加组件b2======================发送消息
this.add(b2);
b2.setSize(100, 20);
b2.setLocation(20, 450 + 10);
b2.addActionListener(this);// 添加监听
b2.setActionCommand("message");// 添加监听命令
// 添加组件b3=========================更改名子用
this.add(b3);
b3.setSize(100, 20);
b3.setLocation(170, 450 + 10);
b3.addActionListener(this);// 添加监听
b3.setActionCommand("name");// 添加监听命令
// 添加组件del==========================删除IP
this.add(del);
del.setSize(100, 20);
del.setLocation(230, 450 + 70 + 25);
del.addActionListener(this);// 添加监听
del.setActionCommand("del");// 添加监听命令
// 添加组件help==========================使用帮助
this.add(help);
help.setSize(100, 20);
help.setLocation(20, 450 + 70 + 25);
help.addActionListener(this);// 添加监听
help.setActionCommand("help");// 添加监听命令
// 添加组件broadcast==========================小区广播
this.add(broadcast);
broadcast.setSize(100, 20);
broadcast.setLocation(20, 450 + 53);
broadcast.addActionListener(this);// 添加监听
broadcast.setActionCommand("broadcast");// 添加监听命令
// 添加组件文本区域========================聊天记录
this.add(jpta);
jpta.setSize(450, 400);
jpta.setLocation(20, 50);
ta.setEditable(false);// 不可编辑
fun1();
// 添加JLabel
this.add(j);
j.setSize(500, 20);
j.setLocation(10, 15);
}
public void fun1() {
String strname = JOptionPane.showInputDialog("请输入一个昵称吧");
if (strname != null) {
this.name = strname;
} else {
JOptionPane.showMessageDialog(this,
"你怎么不写名子啊java简单课题代码???\n还好系统为你创建了名子\n名子为:\n这名真乖");
}
String strip = JOptionPane.showInputDialog("请输入一个IP吧");
if (strip != null) {
if (istrue(strip)) {
strlist[strlists++] = strip;
System.out.println(strlists);
list.setListData(strlist);
} else {
JOptionPane.showMessageDialog(this, "请输入正确的IP");
}
} else {
JOptionPane.showMessageDialog(this,
"你怎么不写好友IP啊???\n你不要好友的IP!你跟谁聊天啊\n"
+ "还好系统可以添加IP和修改IP\n学乖一点哦");
}
JOptionPane.showMessageDialog(this, "你也可以把自己本机的IP添加到上面\n自己跟自己聊天--哈哈");
}
public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();
if (str.equals("ip")) {
System.out.println("添加IP啦");
String ip = JOptionPane.showInputDialog("请输入好友IP");
if (ip != null) {
if (istrue(ip)) {
strlist[strlists++] = ip;
list.setListData(strlist);
System.out.println(strlists);
} else {
JOptionPane.showMessageDialog(this, "请输入正确的IP");
}
}
}
if (str.equals("ipm")) {
System.out.println("修改IP啦");
if (list.getSelectedValue() != null) {
String ss = list.getSelectedValue().toString();
int i = list.getSelectedIndex();
System.out.println("ip为" + ss + " 第 " + i + "数组");
String newip = JOptionPane.showInputDialog("原IP为" + ss
+ "请输入新ip");
if (newip != null) {
if (istrue(newip)) {
strlist[i] = newip;
list.setListData(strlist);
} else {
JOptionPane.showMessageDialog(this, "请输入正确的IP");
}
}
} else {
JOptionPane.showMessageDialog(this, "请选一个IP,好不好");
}
}
if (str.equals("message")) {
System.out.println("发送消息");
if (list.getSelectedValue() != null) {
ipaddres = list.getSelectedValue().toString();
Sa sa = new Sa();
sa.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
} else {
JOptionPane.showMessageDialog(this, "从右下边的IP库\n选一个IP");
}
}
if (str.equals("name")) {
System.out.println("改名子啦");
String strname = JOptionPane.showInputDialog("原名为" + name
+ "\n请输入新名子");
if (strname != null) {
this.name = strname;
} else {
System.out.println("你输入了null,可能是点取消了");
}
}
if (str.equals("help")) {
JOptionPane.showMessageDialog(this,
"添加好友的IP--添加IP\n可以是内网也可以是外网\n确定好友上面也有本程序\n"
+ "然后选择好友的IP就可以发送消息了");
}
if (str.equals("broadcast")) {
JOptionPane.showMessageDialog(this,
"\n你所有的好友(ip)都可以接受到消息\n\n类似群发消息");
S s = new S();
s.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// broadcast();
}
if (str.equals("del")) {
System.out.println("删除IP啦");
if (list.getSelectedValue() != null) {
int i = list.getSelectedIndex();
strlist[i] = null;
list.setListData(strlist);
}
}
}
public void run() {
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(socket
.getInputStream(), "GB2312"));
String line = br.readLine();
System.out.println(line);
if (line.indexOf("6035") != -1) {
StringBuffer b = new StringBuffer(line);
b.delete(0, 4);
int x = 30;
int i = b.length();
for(int j=0;j=i/x;j++){
b.insert(j*x,"\n");
}
line = b.toString();
this.broadcast(line);
JOptionPane.showMessageDialog(this, "通知\n" +name +"说:" + "\t"+line);
}
if (line.indexOf("5306") != -1) {
StringBuffer b = new StringBuffer(line);
b.delete(0, 4);
int x = 30;
int i = b.length();
for(int j=0;j=i/x;j++){
b.insert(j*x,"\n");
}
line = b.toString();
this.s(line);
JOptionPane.showMessageDialog(this, "通知\n" +name +"说:" + line);
}
} catch (Exception e) {
}
}
public void save(String str, int i) {
if (i == 1) {
// 接受的消息
this.ta.setText(ta.getText() + str + "\n");
}
if (i == 2) {// 本地的消息
this.ta.setText(ta.getText() + name + "说:" + str + "\n");
}
}
public void s(String str){
String mess = str ;
try {
Socket ss = new Socket(ipaddres, port);
PrintStream ps = new PrintStream(ss.getOutputStream(), true);
if (mess != null) {
save(mess, 2);
ps.println(name + "说:" + mess);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "实例化失败\n"
+ list.getSelectedValue().toString()
+ "这个IP有问题\n请不要再点了\n确认清楚--\n点修改IP或者删掉");
}
}
public void broadcast(String str) {
String mess = str;
int x = 1;
if (mess != null) {
for (int i = 1; i strlists; i++) {
System.out.println(strlist[i]);
if (strlist[i] != null) {
Socket ss;
try {
ss = new Socket(strlist[i], port);
PrintStream ps = new PrintStream(ss.getOutputStream(),
true);
if (x == 1) {
save(mess, 2);
x++;
}
ps.println(name + "说:" + mess);
ps.close();
ss.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(this, strlist[i]
+ "连接不上\n ip不对或者对方是内网\n请删除或者修改\n以免影响使用");
}
}
}
x = 1;
}
}
public boolean istrue(String str) {
boolean flag = false;
flag = str.matches("(\\d{1,3}).(\\d{1,3}).(\\d{1,3}).(\\d{1,3})");
return flag;
}
public static void main(String[] args) {
new Meeting();
}
}
相关问答
Q1: 给段最简单的java代码 让我新手看一下
最简单java简单课题代码的java代码肯定就是这个java简单课题代码了,如下:
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的新手快速入门java,更好的学习java!
Q2: 求一段简单的java代码
不知道是否理解对了你的意思,大概写了一下:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.io.StringWriter;
public class FileReadAndWrite {
private static final int DEFAULT_BUFFER_SIZE = 1024;
public static void main(String[] args) {
File file = new File("E:/workspace/FileIOTest/src/a.txt");
String str = file2String(file, "UTF-8");
str = str.replace('d', 'f');
string2File(str,"E:/workspace/FileIOTest/src/b.txt");
System.out.println("处理完毕");
}
/**
* 文本文件转换为指定编码的字符串
*
* @param file
* 文本文件
* @param encoding
* 编码类型
* @return 转换后的字符串
* @throws IOException
*/
public static String file2String(File file, String encoding) {
InputStreamReader reader = null;
StringWriter writer = new StringWriter();
try {
if (encoding == null || "".equals(encoding.trim())) {
reader = new InputStreamReader(new FileInputStream(file),
encoding);
} else {
reader = new InputStreamReader(new FileInputStream(file));
}
// 将输入流写入输出流
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
int n = 0;
while (-1 != (n = reader.read(buffer))) {
writer.write(buffer, 0, n);
}
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// 返回转换结果
if (writer != null)
return writer.toString();
else
return null;
}
/**
* 将字符串写入指定文件(当指定的父路径中文件夹不存在时,会最大限度去创建,以保证保存成功!)
*
* @param res
* 原字符串
* @param filePath
* 文件路径
* @return 成功标记
*/
public static boolean string2File(String res, String filePath) {
boolean flag = true;
BufferedReader bufferedReader = null;
BufferedWriter bufferedWriter = null;
try {
File distFile = new File(filePath);
if (!distFile.getParentFile().exists())
distFile.getParentFile().mkdirs();
bufferedReader = new BufferedReader(new StringReader(res));
bufferedWriter = new BufferedWriter(new FileWriter(distFile));
char buf[] = new char[1024]; // 字符缓冲区
int len;
while ((len = bufferedReader.read(buf)) != -1) {
bufferedWriter.write(buf, 0, len);
}
bufferedWriter.flush();
bufferedReader.close();
bufferedWriter.close();
} catch (IOException e) {
e.printStackTrace();
flag = false;
return flag;
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return flag;
}
}
Q3: 求大神帮忙编两个java代码(学生java作业)
第一题: 元素java简单课题代码的复制
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
int[] scores = {91,85,98,62,78,93};
int[] newScores=Arrays.copyOfRange(scores, 0, 5);//复制元素, 左开右闭区间[0,5)
System.out.println(Arrays.toString(newScores));//调用数组工具类java简单课题代码的方法转成字符串并打印
}
}
第二题: 这题虽然使用集合更方便 java简单课题代码, 但却是非常好的一维数组的训练题目.
解法一: 集合解决 随机产生7个不重复的数字很简单
import java.util.HashSet;
import java.util.Random;
public class NumberTest {
public static void main(String[] args) {
HashSetInteger set= new HashSetInteger();//元素不可重复的无序集合
Random rd=new Random();//随机产生器
while(set.size()7) {
set.add(rd.nextInt(36)+1);//产生1~36的随机数
//如果元素重复, 那么添加不上去
}
System.out.println(set);
}
}
解法二:一维数组 ,解决产生7个数字, 并升序排列
int[] nums 数组存储1~36个数组
boolean[] flags 数组存储的是和nums数组一一对应的true或者false,如果使用java简单课题代码了就标记为true.,如果没有使用标记为false,
例如 随机产生java简单课题代码了一个下标0 ,那么查看flags[0] ,如果是true, 那么说明该元素已经使用了,重新产生一个随机数, 如果是false ,那么表示nums[0]没有被使用
具体代码如下(稍微留个尾巴, 就是中不中的判断, 可以把两个数组都升序排序,然后元素一一比较,全部相同就是中了)
import java.util.Arrays;
import java.util.Random;
public class NumberDemo {
public static void main(String[] args) {
int[] nums= new int[36];//长度为36的数组 ,默认全是0
for (int i = 0; i nums.length; i++) {//利用for循环赋值1~36
nums[i]=i+1;
}
boolean[] flags=new boolean[nums.length];//长度和nums相同的数组,默认值全是false ,表示全部没有使用过
//用boolean值表示对应的nums里的元素是否被使用
int[] result=new int[7];//存储结果
Random rd = new Random();
for (int i = 0; i result.length; i++) {
int temp=rd.nextInt(nums.length);//随机产生下标
//System.out.println(Arrays.toString(result));
if(flags[temp]) {//如果已经被使用,那么i-1,并在此循环
i--;
//System.out.println("号码"+nums[temp]+"已经存在.再次循环");
}else {
result[i]=nums[temp];
flags[temp]=true;//标记true表示已经使用了
}
}
System.out.println("原始排序:"+Arrays.toString(result));
Arrays.sort(result);//升序排列
System.out.println("升序排列:"+Arrays.toString(result));
}
}
Q4: 求一个简单java程序代码,谢谢
public class TestStar {
public static void main(String[] args) {
String star = "*";
for (int i = 0; i 5; i++) {
if (i == 0) {
System.out.print(" " + star);
System.out.println();
}
if (i == 1) {
for (int z = 0; z 4; z++) {
System.out.print(" " + star);
}
System.out.println();
}
if (i == 2) {
System.out.print(" ");
for (int x = 0; x 3; x++) {
System.out.print(" " + star);
}
System.out.println();
}
if (i == 3) {
for (int y = 0; y 2; y++) {
System.out.print(" " + star + " ");
}
}
}
}
}
是好使的 但是我没找到画五角星有什么规律(五角星好象不是正规图形吧?)如果还有什么要求的话 补充问题(如果是用*填充所有的东西 不包括 “ ”的话 我可以重新再给你写一个)
Q5: 一个简单的Java程序代码?
package com.zpp;public class Charge {
public static void main(String [] args) {
if(args.length ==0) {
System.out.println("parameter error!");
System.out.println("java com.zpp.Charge [int]");
return;
}
int min = Integer.parseInt(args[0]);
double money = 0.0;
if (min = 0) {
money =0.0;
System.out.println("not money");
} else if (min = 60) {
money = 2.0;
} else {
money = 2.0 + (min - 60) * 0.01;
}
System.out.println("please pay: " + money);
}
} 编译:javac -d . Charge.java运行:java com.zpp.Charge 111
关于java简单课题代码和java毕业设计的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。








