我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

java简单课题代码 java课设课题

大一java课题代码,要求:复制粘贴后就能用的,1000行以上,可追加分数,看你的是不是没重复的,下载的不

import java.awt.Container;

创新互联是专业的下城网站建设公司,下城接单;提供成都网站建设、成都网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行下城网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

import java.io.*;

import java点虐 .*;

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, "你好像没有输入消息内容");

}

}

}

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 = "这名真乖";// 用记名子,可以更改

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,

"你怎么不写名子啊???\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();

}

}

给段最简单的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!

一个简单的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课设课题
标题URL:http://shouzuofang.com/article/ddidogp.html

其他资讯