昨天捣鼓了一天的eclipse,自我感觉良好,感觉eclipse有点像DELPHI,一切为插件的口号让人激动不已,当然eclipse可以作为C++的IDE,前提是安装c/c++ide插件,具体下载http://www.eclipse.org/downloads/,
ECLIPSE 包括JDT(标准插件)和PDE 插件开发环境,更让人不可思议的是,它居然有完全汉化的版本,就连帮助也是全汉化的,汉化语言包是作为插件安装进入ide的,像我这样外语不好的朋友可以有福了.
不过Language Pack有大约1几个文件,都在http://download.eclipse.org/eclipse/downloads/drops/L-3.1.1_Language_Packs-200510051300/index.php,全都要下载下来,镜像下载点个人感觉台湾的yat-sen大学的快,浙江大学的下载点估计已经关闭了(大陆的就是不行啊),下载后将这些文件解压,每个目录下面都有一个eclipse目录,大家可以之间把它们覆盖到你的eclipse安装目录下.
不过我建议把他们全部复制到一个单独的目录里,然后在eclipse安装目录下建立一个links目录,然后在links目录下建立一个*.link的文本文档,在文档里写入path=C:\\eclipse311\\lag路径(我的语言包是放在C:\eclipse311\lag下的),然后重新打开eclipse,一个几乎全中文的界面就跳出来了.
月份:2006年6月
客户端到服务端,c/s结构,用户验证
java真的很难写啊,用惯了Delphi,C#之类容易调试的编程工具,
没办法一点一点的写吧,
今天又写了个从客户端发送字符串,到服务端验证的代码,刚好把前一次的用户验证类用上,不过做了些修改.
通过这段时间的写代码,渐渐的对java也熟悉些了,速度也慢慢快起来了,自己心中窃喜
附件:talk.rar,3620 bytes
从客户端往服务端发送消息的代码
客户端
public class TalkClient {
public static void main(String[] args) {
// Create application frame.
ClientSend cs = new ClientSend();
TalkClientFrame frame = new TalkClientFrame(cs);
// Show frame
frame.setVisible(true);
}
}
//----------------------------------------------------
import java.net.*;
public class ClientSend {
private DatagramSocket ds_CSend;
private DatagramPacket dp_CSend;
public ClientSend(){
try{
ds_CSend = new DatagramSocket(8080);
}
catch(Exception e){
e.printStackTrace();
}
}
public void Sended(byte[] buf,String sip){
try{
dp_CSend = new DatagramPacket(buf,buf.length,InetAddress.getByName(sip),8888);
ds_CSend.send(dp_CSend);
}
catch(Exception e){
e.printStackTrace();
}
}
}
///----------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class TalkClientFrame extends Frame {
private List lst = new List(6);//存放对话内容
private TextField tf_Data = new TextField(20);//存放发送内容
private TextField tf_ip = new TextField(15);//存放IP和PORT;
private ClientSend cs;
public TalkClientFrame(ClientSend cs) {
this.cs = cs;
tf_ip.setText("127.0.0.1");
Panel p_Data = new Panel();//放置tf_Data,tf_ip的容器
//-----------------------布局-----------------------------------
this.add(lst,"Center");
this.add(p_Data,"South");
p_Data.add(tf_ip,"West");
p_Data.add(tf_Data,"East");
tf_Data.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
//
tf_Dataactionperformed(evt);
}
});
//----------------------------------------------------------------
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu();
MenuItem menuFileExit = new MenuItem();
menuFile.setLabel("文件(F)");
menuFileExit.setLabel("退出(X)");
// Add action listener.for the menu button
menuFileExit.addActionListener
(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (tf_Data.getText().length()>0)
TalkClientFrame.this.windowClosed();
}
}
);
menuFile.add(menuFileExit);
menuBar.add(menuFile);
setTitle("TalkClient");
setMenuBar(menuBar);
setSize(new Dimension(350, 400));
// Add window listener.
this.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
TalkClientFrame.this.windowClosed();
}
}
);
}
void tf_Dataactionperformed(ActionEvent e){
byte[] buf = tf_Data.getText().getBytes();
String strIp = tf_ip.getText();
try{
cs.Sended(buf,strIp);
}
catch(Exception ex){
ex.printStackTrace();
}
tf_Data.setText("");
}
/**
* Shutdown procedure when run as an application.
*/
protected void windowClosed() {
// TODO: Check if it is safe to close the application
// Exit application.
System.exit(0);
}
}
服务端
public class talkServer {
public static void main(String[] args) {
// TODO: Add your code here
talkRecv tR = new talkRecv();
tR.Recved();
}
}
//------------------------------------------------
import java.net.*;
public class talkRecv {
private DatagramSocket ds_Recv;
private DatagramPacket dp_Recv;
public boolean b_stop=true;
public talkRecv(){
try{
ds_Recv = new DatagramSocket(8888);//将8888端口作为接受端口
byte[] buf = new byte[1024];
dp_Recv = new DatagramPacket(buf,1024);
}
catch(Exception e){
e.printStackTrace();
}
}
public void Recved(){
while(b_stop){
try{
ds_Recv.receive(dp_Recv);
String str_info = new String(dp_Recv.getData(),0,dp_Recv.getLength());
System.out.println(" ip:"+dp_Recv.getAddress().getHostAddress());
System.out.println("port:"+dp_Recv.getPort());
System.out.println("data:"+str_info);
}
catch (Exception e){
e.printStackTrace();
}
}
}
}
//------------------------------------------------
这几个类都没怎么考虑对象的释放问题,这个问题希望那位大大能够关注一下,给小弟一点指点,小弟感激不禁
一个查询登陆数据验证的程序
有两个文件
public class talkServer {
/*中间件主程序
*/
public static void main(String[] args) {
// TODO: Add your code here
db_Access db= new db_Access();
if(db.loging(args[0],args[1])){
System.out.println("验证通过");
}
else{
System.out.println("验证失败");
};
}
}
///////////////////////////////////////////////////////////////////////
import java.sql.*;
import java.util.*;
public class db_Access {
private Connection db_connect;//定义与数据库进行连接的对象
private ResultSet rs; //定义数据库查询结果对象
private Statement st; //定义数据库查询对象
// private Vector vt; //定义结果数组
public db_Access(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//知道是返回一个JDBC-ODBC的桥驱动程序对象,但是在这里这样写有什么作用
//就不得而知了
String url ="jdbc:odbc:talkdb";
db_connect = DriverManager.getConnection(url);
st = db_connect.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY); //创建statement接口对象实例
}
catch(Exception e){
//可以把异常做成一个类,不知道有没有现成的好类可以用的
e.printStackTrace();
}
}
public boolean loging(String un,String pd){
String strSQL = "SELECT count(id) AS aid FROM userinfo WHERE (username ='"
+ un +"')AND(password ='" + pd +"')" ;
try{
rs = st.executeQuery(strSQL); //执行设计好的sql语句
rs.next();
if (rs.getInt(1)==0){ //这里的getInt()的字段索引居然是1,那么0是什么哪?
return false;
}
else{
return true;
}
}
catch(Exception e){
e.printStackTrace();
}
return false;
}
}
数据库格式为 id username password
有个问题,为什么当我故意查找错误的username和password的时候,
rs.getInt老是抛出"非法游标状态"的异常?正确的密码组合到没事情
我用的是select count啊,应该返回0这个值的啊,亲娘唉,真令人费解啊.
明天又要出发去武引勘测渠道了
托老天爷的福,下了一场大雨。让我们好好的休息了三天,明天早上领导要求5:00到单位集合,统一吃早饭,然后出发,一组直奔金华镇,一组到复兴镇。我可能跟第一组先到金华镇。
又要辛苦了,要早点休息。明天早上不要迟到。
classpath 问题
很简单的类的调用,但是在JCREAT中用工程和工作空间能够编译运行,但是在cmd下用java命令却运行不了
package killgod;
public class A {
/**
* Method sayHellow
*
*
*/
public void sayHellow() {
// TODO: Add your code here
String s1 = "我要发财",s2 = "我要发财";
if (s1 == s2 ){
System.out.println("第一次试验:"+s1);
}
else System.out.println("世界和平");
s1 = new String("我要发财");
s2 = new String("我要发财");
if (s1 == s2 ){
System.out.println("第2次试验:" + s1);
}
else System.out.println("第2次试验:世界和平");
}
}
运行类
package killgod;
public class SencondDemo {
public int x = 1;
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
// TODO: Add your code here
if(args.length > 0 ){
System.out.println("第一个参数是 "+args[0]);
}
else{
new SencondDemo().callA(new A());
}
}
/**
* Method callA
*
*
* @param a
*
*/
public static void callA(A a) {
// TODO: Add your code here
a.sayHellow();
}
}
我在cmd下面使用了 set CLASSPATH = ?????的命令,结果还是没有效果,真是奇怪啊!
看来classpath问题要好好研究一下了。
一个猴子扮苞谷的程序
先写点习作熟悉一下JAVA的工作
class monky
{
int[] goods = new int[100];
//getGood作为litte monky的行为成员
void getGood(int good,int i)
{
goods[i] = good;
}
//开始计算扳了多少
void count()
{
int all =0;
for(int i=0;i<100;i++)
{
all = all+goods[i];
System.out.print(goods[i]+",");
}
System.out.println(" ");
System.out.print("总重:"+all);
}
}
class monkyPlay
{
public static void main(String[] args)
{
monky mk = new monky();
for(int i=0;i<100;i++)
//随机产生不同重量的苞谷
mk.getGood((int)(Math.random()*3000),i);
mk.count();
}
}
从一段小程序重新认识自己
这次主要是看如果自己现在就开始动手写,最多能够写到哪一步,于是随便找了一个Clock 的代码,一边抄写一边理解,
这是我的学习方法,并不要求全部搞懂,但是每一步所完成的功能要知道,然后对照自己过去的编程经验,期望能够找到自己现在的水平在哪里!
下面是学习过程
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.awt.image.*;
public class Clock extends Applet implements Runnable, MouseListener,
ActionListener {
//写到这里发现这个Clock居然是Applet的子类,遇到看不明白的当然是手册伺候了,
//翻阅资料发现这个所谓Applet在JDKdom中的介绍为
//"是一种不适合单独运行但可嵌入在其他应用程序中的小程序。"完全看不懂
//而他的定义是public class Applet extends Panel ,^_^居然是Panel的子类
//这样我大概知道了这个Applet应该是一个容器类
//再看这家伙的方法,哇一大堆url,Image一看就是个html像,我心里合计,
//小样!别以为改了名字爷就认不 出你了。
//现在前面看明白了,implements就又有点不了了,决定先放一下,不求甚解从来就是
//本人的优良品德之一。
Image image,image1;
Toolkit tool;
JPanel panel;
Graphics gg;
int width,height,width1,height1;
Thread thread,thread2;
MediaTracker m;
double angel1=0,angel2=0;
int xsec,ysec,xsec2,ysec2,xmin,ymin,xmin2,ymin2,xhou,yhou,xhou2,yhou2;
int c = 0,xstr = 235,ystr = 253;
int y = ystr;
JButton button1 = new JButton();
JButton button2 = new JButton();
JButton button3 = new JButton();
JButton button4 = new JButton();
AudioClip music;
Color colorh = Color.GREEN,colorm= Color.BLACK,colors= Color.YELLOW;
String[] string = new String[5];
int kk = 0;
//上面一大堆罗里吧索的终于结束了
public void init()
{
//等会这个init咋那么眼熟,好像在哪里见过,哦。。。。。
//Applet方法成员之一,立即手册之,
//"由浏览器或 applet viewer 调用,通知此 applet 它已经加载到系统中。"
//看这个意思有点像把主对象容器初始化。
this.setLayout(new BorderLayout());
this.setBackground(Color.BLACK);
tool = getToolkit();
//到这里又看不懂了,怎么getToolkit()既没有对象也没有参数的,这样也可以啊!
//不管了接着看吧
image = tool.getImage("image.PNG");
//看吧PNG网页的东东来了吧
m = new MediaTracker(this);
m.addImage(image,0);
try
{
m.waitForID(0);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
//怎么多媒体也出来了,这个倒霉的程序员,没办法手册依旧
//MediaTracker 类是一个跟踪多种媒体对象状态的实用工具类
//要使用媒体跟踪器,需要创建一个 MediaTracker 实例,
//然后对每个要跟踪的图像调用其 addImage 方法。
//另外,还可以为每个图像分配一个惟一的标识符。
//此标识符可控制获取图像的优先级顺序。它还可用于标识可单独等待的惟一图像子集。
//具有较低 ID 的图像比具有较高 ID 的图像优先加载。
//这样后面的都大概看明白了,就是加载了一张图片。
//不由大呼,不愧是JAVA这样简单的操作也搞的如此复杂,偶喜欢。
width1 = image.getWidth(this);
height1 = image.getHeight(this);
width = this.width;
height = this.height;
//这两句有区别吗?
this.addMouseListener(this);
//姑且认为是在主容器上添加一个作用于主容器的鼠标事件吧
button1.setText("时针颜色");
button1.addActionListener(this);
button2.setText("分针颜色");
button2.addActionListener(this);
button3.setText("秒针颜色");
button3.addActionListener(this);
button4.setText("选择皮肤");
button4.addActionListener(this);
button1.setBackground(Color.BLACK);
button1.setForeground(Color.WHITE);
button2.setBackground(Color.BLACK);
button2.setForeground(Color.WHITE);
button3.setBackground(Color.BLACK);
button3.setForeground(Color.WHITE);
button4.setBackground(Color.BLACK);
button4.setForeground(Color.WHITE);
//为什么Color后颜色成员有大小写区分哪?
JPanel panel = new JPanel();
//手册:JPanel 是一般轻量级容器。不解
panel.setBackground(Color.BLACK);
panel.setLayout(new FlowLayout(FlowLayout.CENTER));
panel.add(button1);
panel.add(button2);
panel.add(button3);
panel.add(button4);
this.setLayout(new BorderLayout());
this.add(panel,BorderLayout.SOUTH);
string[0] = "时间就像海绵里水";
string[1] = "只要挤总会有的";
string[2] = "珍惜身边每一个人";
string[3] = "因为随着岁月流逝,";
string[4] = "他们将......";
//你不当程序员你还想当诗人啊!
//我有这样想过啊
//省省吧,好好做你这个程序员这么有前途的职业去吧。
image1 = createImage(getWidth(),getHeight()-35);
//又是一句没头没脑的东西。
gg = image1.getGraphics();
}
public void start()
{
//亲娘耶,这就开始了?
if (thread == null)
{
thread = new Thread(this);
thread.start();
}
if (thread2 == null)
{
thread2 = new Thread(new thread2());
//new一个new的自己??
thread2.start();
}
}
public void paint(Graphics g)
{
super.paint(g);
g.drawImage(image1,0,0,this);
Date date = new Date();
int hour = date.getHours();
int min = date.getMinutes();
int sec = date.getSeconds();
String m = Integer.toString(hour)+":"+Integer.toString(min)+":"
+ Integer.toString(sec);
//好像这样也可以 SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
// String m = sdf.format(date);
double ans = (Math.PI/30)*min;
double anm = (3.1415926535897931D /30)*min;
double anh = ((hour +min/60.0)*(2*Math.PI/12));
xsec2 = 172 + (int) (45 * Math.sin(ans));
ysec2 = 165 - (int) (45 * Math.cos(ans));
xsec = 172 - (int) (13 * Math.sin(ans));
ysec = 165 + (int) (13 * Math.cos(ans));
xmin2 = 172 + (int) (40 * Math.sin(anm));
ymin2 = 165 - (int) (40 * Math.cos(anm));
xmin = 172 - (int) (10 * Math.sin(anm));
ymin = 165 + (int) (10 * Math.cos(anm));
xhou = 172 + (int) (30 * Math.sin(anh));
yhou = 165 - (int) (30 * Math.cos(anh));
xhou2 = 172 - (int) (10 * Math.sin(anh));
yhou2 = 165 + (int) (10 * Math.cos(anh));
g.setColor(colors); //秒针
g.drawLine(xsec, ysec, xsec2, ysec2);
g.setColor(colorm); //分针
g.drawLine(xmin, ymin, xmin2, ymin2);
g.setColor(colorh); //时针
g.drawLine(xhou2, yhou2, xhou, yhou);
g.setColor(Color.RED);
g.fillOval(169,162,9,9);
g.drawString(m,150,100);
g.setColor(Color.RED);
g.drawString(string[0], xstr, y);
g.drawString(string[1], xstr, y + 20);
g.drawString(string[2], xstr, y + 40);
g.drawString(string[3], xstr, y + 60);
g.drawString(string[4], xstr, y + 80);
}
public void update(Graphics g)
{
paint(g);
}
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
// TODO: Add your code here
}
/**
* Method run
*
*
*/
public void run() {
// TODO: Add your code here
while (true)
//这个true在这里有意义吗?
{
try
{
thread.sleep(1000);
gg.setColor(Color.WHITE);
gg.fillRect(0,0,width,height);
gg.drawImage(image,110,110,width1,height1,this);
repaint();
}
catch (Exception e)
{
System.out.print(e.getMessage());
}
}
}
private class thread2 implements Runnable
{
//前面已经有个thread2了,这里有冒出来一个,而且是Runnable接口
//前面那个thread2是Thread类
//难道纯属于该程序员在练习两种线程的创建方法吗?这个问题先放一放
public void run()
{
while (true)
{
try
{
thread2.sleep(1000);
}
catch(Exception e)
{
}
y--;
if (y<=5)
{
y=ystr;
}
repaint();
}
}
}
//一堆鼠标事件
public void mouseClicked(MouseEvent e) {
// TODO: Add your code here
System.out.print(e.getX());
System.out.print(e.getY());
}
public void mousePressed(MouseEvent e) {
// TODO: Add your code here
}
public void mouseReleased(MouseEvent e) {
// TODO: Add your code here
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void fileSelect()
{
JFileChooser choose = new JFileChooser();
//为用户选择文件提供了一种简单的机制
choose.setFileSelectionMode(JFileChooser.FILES_ONLY);
choose.setCurrentDirectory(new File("."));
//new File(".")?????????
choose.setFileFilter(new javax.swing.filechooser.FileFilter()
{
public boolean accept(File file)
{
String name = file.getName().toLowerCase();
return name.endsWith(".gif")||name.endsWith(".jpg")
||name.endsWith(".jpeg")||file.isDirectory();
}
public String getDescription()
{
return "图片文件";
}
});
//这里看起来java程序的组件应该全都是动态创建的了。难怪很难写。
int result = choose.showOpenDialog(this);
String name = null;
if(result == JFileChooser.APPROVE_OPTION)
{
name = choose.getSelectedFile().getAbsolutePath();
}
image = tool.getImage(name);
m.addImage(image,0);
try{
m.waitForAll();
} catch (Exception e){
System.out.print(e.getMessage());
}
}
public void actionPerformed(ActionEvent e) {
// TODO: Add your code here
if(e.getSource() == button1||e.getSource()==button2||e.getSource() ==button3){
JColorChooser Choose = new JColorChooser();
}
}
}
写到这里,机器中病毒了,而且自己也觉得没必要再继续写下去了
所有看不懂的一概跳过,最后发现还是从头学比较好
要出差20天
住到乡下勘测,可能接触不到网络了。
开始构思学习日记的BLOG视图设计
我已经在学习日记的开源社区的问题跟踪系统提交这个任务20,简述如下:
|
这个想法起源于一位网友javar的建议:http://www.learndiary.com/disGoalContentAction.do?goalID=1287
已经完成的添加私人目标和日记的支持也来自他的建议。http://www.learndiary.com/disDiaryContentAction.do?goalID=2086