求JAVA编程代码…………
下面是WINDOW界面的代码,用JAVA SWING写的。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PlusWhile {
//主面板
private JFrame mainTop = null;
private JPanel inPanel = null; //输入面板
private JPanel outPanel = null;//输出面板
private JButton count = null; //按钮
private JTextField inText = null; // 输入文本框
private JTextField result = null;//结果文本框
private JLabel resultOut = null;//输出提示
private JLabel remindIn = null;//输入提示
//初始化方法
private void init() {
//组件实例化
mainTop = new JFrame("阶乘计算器");
inPanel = new JPanel();
outPanel = new JPanel();
count = new JButton("计算");
inText = new JTextField(10);
result = new JTextField(10);
resultOut = new JLabel("计算的结果:");
remindIn = new JLabel("请输入要计算的正整数:");
//添加输入组件
inPanel.add(remindIn);
inPanel.add(inText);
inPanel.add(count);
//添加输出组件
outPanel.add(resultOut);
outPanel.add(result);
result.setEnabled(false);
//设置布局样式
mainTop.setLayout(new BorderLayout());
//主面板添加组件
mainTop.add(inPanel, BorderLayout.NORTH);
mainTop.add(outPanel, BorderLayout.SOUTH);
//设置监听
count.addActionListener(new ButtonListener());
//设置屏显位置
mainTop.setLocation(350 , 300);
mainTop.pack();
mainTop.setVisible(true);
mainTop.setAlwaysOnTop(true);
//设置关闭事件
mainTop.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//监听类
private class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
int inputNum = 0;
String input = inText.getText();
//若输入为非数字,提示错误
try {
inputNum = Integer.parseInt(input);
}catch(Exception e) {
inputNum = -1;
}
//输入数值小于0,提示错误
if(inputNum 0) {
inText.setText("请输入正确的数值!");
result.setText("");
}
else if(inputNum == 0) {//输入值为0处理
result.setText("1");
}
else {//输入值为正整数,计算阶乘
int temp = inputNum;
while(inputNum 1) {
temp *= --inputNum;
}
result.setText(temp + "");
}
}
}
//入口方法
public static void main(String[] args) {
new PlusWhile().init();
}
}
有什么不明白的继续补充,呵呵。 加点儿分不。
最浪漫的编程代码可复制手机
代码分享:
#include
#include
int main()
{undefined
double y, x, z;
printf("那一天\n");
printf("第一次遇见你\n");
printf("忘不了\n");
printf("你的容颜\n");
printf("若轻云之蔽月,如流风之回雪\n");
printf("\n\n\n");
printf("其实\n");
printf("有一句话\n");
printf("我一直想对你说:\n");
for(y= 2.5; y = -1.6; y = y - 0.2)
{undefined
for(x = -3; x {undefined
(pow((x*x + y*y - 1), 3) || (x-2.4 x-1)
|| (((x2.2)
|| (x3.4 x-1 y|| (y-1 y2.2)
) ? printf("*") : printf(" ");
}
printf("\n");
}
getchar();
}
代码解析:
1、pow函数是计算平方的函数,pow((x*x + y*y - 1), 3) 2、x-2.4 x-1
是画"I"。
3、剩下的3个分别是U的三边。
4、内外层的for是确定画的位置。
大一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, "你好像没有输入消息内容");
}
}
}
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();
}
}
最浪漫的编程代码可复制
import numpy as np
import time
import matplotlib.pyplot as plt
def plot_love(numbers):
for k in range(numbers):
time.sleep(0.05)
def f(x, love=50):
y = x ** (2/3) + 0.9 * np.sqrt(3.3-x**2)*np.sin(love*np.pi*x)
return y
x = np.linspace(0, 2, 1500)
y = [f(i, k) for i in x]
plt.plot(x, y, color='red', linewidth=5)
plt.plot(-x, y, color='red', linewidth=5)
plt.xlim(-2, 2)
plt.show()
plot_love(100)
java编程代码,要完整的代码,可以运行出来的。谢谢!
Course.java
public class Course {
private String name;//课程名
private String id; //编号
private String selectId; //选修课编号
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getSelectId() {
return selectId;
}
public void setSelectId(String selectId) {
this.selectId = selectId;
}
}
程序员的表白代码
第一条
语言:Java
代码翻译:
直到死之前,每天爱你多一点
代码:
while (life end) {
love++;
}
第二条
语言:C语言
代码翻译:
I can not say Hello to the World without u.
代码:
#inclde stdio.h
int main() {
printf("Hello World\n");
retrn 0;
}
// I can not say Hello to the World without u.
第三条
语言:python
代码翻译:
山无陵, 江水为竭, 冬雷震震, 夏雨雪, 天地合, 乃敢与君绝!
代码:
if(mountain.arris==None):
if(river.water==None):
if(winter.thunder==True):
if(summer.snow==True):
if(sky.height==ground.height):
i.withyou=False
else:
i.withyou=True
第四条
语言:Erlang代码
代码翻译:
深圳相遇,至死不渝
代码:
-module(you_and_me).
-export([start/1]).
-record(person,{name,address,status}).
start(Name) -
one_world(Name).
one_world(Name) -
Me=#person{name=Name, address=sz, status=alive},
when_meet_you(Me).
when_meet_you(Person = #person{name=me}) -
start_to_love_you(Person);
when_meet_you(_) -
ignore.
start_to_love_you(Person) -
io:format("~p: I Love You!~n", [Person#person.name]),
keep_to_love_you(Person).
keep_to_love_you(Person=#person{name=me, status=die}) -
say_goodbye(Person),
see_you_next_world(Person#person.name);
keep_to_love_you(Person = #person{name=me}) -
io:format("~p: I Love You Forever!~n", [Person#person.name]),
keep_to_love_you(Person).
say_goodbye(Person) -
io:format("~p: see you next world!~n", [Person#person.name]).
see_you_next_world(Name) -
one_world(Name).
第五条
语言:Java语言
代码翻译:
爱你到天荒地老
代码:
while(!world.destroy){
System.out.println("i love you");
}
第六条
语言:C语言
代码翻译:
两隔的世界;
无名的信件;
短暂的停留;
长久的记忆;
说这么多,只是想说:我想你了。
代码:
#include stdio.h
int main()
{
double world;
unsigned letter;
short stay;
long memories;
printf("I miss you.\n");
return 0;
}
第七条
语言:C++
代码翻译:
我生为卿生,卿生赴我媒,同心两相知,长命无绝衰
代码:
//人
class Person{
//...
private:
void* id; //本我
void* ego; //自我
void* superego; //超我
};
//伴侣——不分你我地联合
union Couple{
void* you;
void* me;
};
//生生世世的伴侣们
vectorCouple** timelessCouples = new vectorCouple*();
//有你、有我的世界
int main(int argc, char** argv){
//亘古...
timeFlies();//...岁月...
Person* me = new Person();//我
timeFlies();//...岁月...
Person* you = new Person();//你
timeFlies();//...岁月...
if(check(time, place, you, me) == true){
//如果时间、地点,还有你,都没有异见,我愿陪你,从亘古到永远
Couple * newCouple = new Couple();
newCouple-me = you;
timelessCouples-push_back(newCouple);
}
timeFlies();//...岁月...
//永远...
return 0;
}
第八条
语言:JavaScript
代码翻译:
春风十里不如你
代码:
var you = function from_future_import(){};
var spring = {
'breezing':true,
'length':10
};
var i = [];
i.sort([spring,you])==[you,spring]
Java编程求代码
这个是需要用JAVASCRIPT或者JQUERY 解决吧,这属于JSP的问题吧。
思路 :如果是JQUERY 需要定义一个function 方法名(参数)将按钮A绑定一个双击事件 (参数是A或者是其对应的ascii码 65)如果参数是大写的A 则需要在方法体内将其转成 对应ascii码。具体复制的实现 :如果A按钮 input type="button" id = "a"在一个DIV内 如div id ="div"
input type="button" id = "a"A/input
/div
只需要 获取当前ID为div的div$("#div") 之后再起后边加入通过append方法在A的后边加入按钮B(A+1)(所以首先应该将传入的参数65 加1获取其下一个字母) 。具体实现$("#div")
.append(input type="button" 双击事件="方法名(新获得的字母)"新获得的字母/input);取消参数按钮绑定 给新获得的字母绑定双击事件。
急!!!简单JAVA编程代码
public class Test {
public static void main(String[] args) {
MyRectangle rec = new MyRectangle(3, 5);
MyRectangle square = new MySquare(4);
System.out.println(rec.toString());
System.out.println(square.toString());
}
}
class MyRectangle{
protected double width;
protected double length;
public MyRectangle(double length, double width){
this.width = width;
this.length = length;
}
public double getLength() {
return length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getArea(){
return this.width * this.length;
}
public String toString(){
return "长方形的长为:" + length + ", 宽: " + width + ", 面积为:" + getArea();
}
}
class MySquare extends MyRectangle{
public MySquare(double length){
super(length, length);
}
public double getArea(){
return Math.pow(super.width, 2);
}
public String toString(){
return "正方形边长为: " + super.length + ", 面积为: " + getArea();
}
}
----------测试
长方形的长为:3.0, 宽: 5.0, 面积为:15.0
正方形边长为: 4.0, 面积为: 16.0