1. 首页 > 科技

java编程用在一些网络小程序上比较好?比如风险预测,算命和网页审查工具等,还可以干什么?

java编程用在一些网络小程序上比较好?比如风险预测,算命和网页审查工具等,还可以干什么?

用JAVA编写一个简单的算命程序

public class Salary {

/**

* @param args

*/

public static void main(String[] args) {

//用继承,重写方法,都是调用的wages()方法

Person personManager = new Manager();

System.out.println("这个人的工资是:"+personManager.wages());

Person personEngineer = new Engineer();

System.out.println("这个人的工资是:"+personEngineer.wages());

Person personWorker = new Worker();

System.out.println("这个人的工资是:"+personWorker.wages());

}

}

//人类

class Person {

public String wages(){

return "";

}

}

//经理类

class Manager extends Person{

public String wages(){

return "5000/月";

}

}

//工程师类

class Engineer extends Person{

public String wages(){

return "3000/月";

}

}

//工人类

class Worker extends Person{

public String wages(){

return "2000/月";

}

}

帮忙编一个JAVA网络小程序,随便一个都行~

聊天系统

客户端类的

so=new Socket("服务端机子的IP",9000);

服务端机子的IP 手动加上去

使用方法:

服务器类在A运行

客户端类在B运行 IP填写A的 就可以聊天了

服务器类

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.IOException;

import java.io.PrintWriter;

import java.ServerSocket;

import java.Socket;

import java.util.Scanner;

import javax.swing.*;

public class fuwuqi extends JFrame implements ActionListener {

JTextArea ja;

JScrollPane jp;

static JTextField jt;

JButton jb;

ServerSocket ss;

Socket so;

PrintWriter pw;

Scanner sc=new Scanner(System.in);

fuwuqi()

{

ja=new JTextArea();

jp=new JScrollPane(ja);

jt=new JTextField(10);

jb=new JButton("发送");

this.add(jp);

this.add(jt);

this.add(jb);

this.setLayout(null);

jp.setBounds(10, 10, 300, 180);

jt.setBounds(10, 200, 200, 20);

jb.setBounds(240, 200, 70, 20);

jb.addActionListener(this);

jt.addActionListener(this);

this.setResizable(false);

this.setLocation(300, 210);

this.setTitle("服务端 - 聊天");

this.setSize(325,270);

this.setVisible(true);

this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);

try {

ss=new ServerSocket(9000);

so=ss.accept();

pw=new PrintWriter(so.getOutputStream(),true);

Scanner sc=new Scanner(so.getInputStream());

while(true)

{

ja.append("客户端说:"+sc.nextLine()+"\\r\

");

}

} catch (IOException e) {

System.out.println("端口被占用");

}

}

public static void main(String[] args) {

new fuwuqi();

}

public void actionPerformed(ActionEvent e) {

String a=jt.getText();

pw.println(a);

ja.append("我说:"+a+"\\r\

");

jt.setText("");

}

}

客户端类

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.IOException;

import java.io.PrintWriter;

import java.ServerSocket;

import java.Socket;

import java.util.Scanner;

import javax.swing.*;

public class kehu extends JFrame implements ActionListener {

JTextArea ja;

JScrollPane jp;

static JTextField jt;

JButton jb;

ServerSocket ss;

Socket so;

PrintWriter pw;

Scanner sc=new Scanner(System.in);

kehu()

{

ja=new JTextArea();

jp=new JScrollPane(ja);

jt=new JTextField(10);

jb=new JButton("发送");

this.add(jp);

this.add(jt);

this.add(jb);

this.setLayout(null);

jp.setBounds(10, 10, 300, 180);

jt.setBounds(10, 200, 200, 20);

jb.setBounds(240, 200, 70, 20);

jb.addActionListener(this);

jt.addActionListener(this);

this.setResizable(false);

this.setLocation(300, 210);

this.setTitle("客户端 - 聊天");

this.setSize(325,270);

this.setVisible(true);

this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);

try {

so=new Socket("服务端机子的IP",9000);

//so=new Socket("127.0.0.1",9000);

//so=new Socket("服务器IP",9000);

pw=new PrintWriter(so.getOutputStream(),true);

Scanner sc1=new Scanner(so.getInputStream());

while(true)

{

ja.append("服务器说:"+sc1.nextLine()+"\\r\

");

}

} catch (IOException e) {

System.out.println("端口被占用");

}

}

public static void main(String[] args) {

new kehu();

}

public void actionPerformed(ActionEvent e) {

String a=jt.getText();

pw.println(a);

ja.append("我说:"+a+"\\r\

");

jt.setText("");

}

}

java小程序

Swing 编程,

package dong;

import java.awt.Color;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.ButtonGroup;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPasswordField;

import javax.swing.JRadioButton;

import javax.swing.JTextField;

//import qq.dao.UserDao;

//import qq.model.User;

public class QQZC extends JFrame{

    /**

     * 注册界面

     */

    private static final long serialVersionUID = -4153201762431218646L;

    Icon box;

    Icon box1;

    JLabel label;

    JTextField nic;

    JTextField mima;

    JTextField xb;

    JTextField nl;

    JTextField sr;

    JTextField dizhi;

    JRadioButton bold;//男

    JRadioButton vertical;//女

    JRadioButton vertical1;

    JLabel button;

    JComboBox iconsBox;

    JButton labelq;

    JButton labelt;

    String[] iconFiles = {"image\\44.jpg","image\\100.jpg","image\\101.jpg"

            ,"image\\107.jpg","image\\13.jpg","image\\102.jpg","image\\103.jpg","image\\104.jpg",

            "image\\105.jpg","image\\115.jpg","image\\114.jpg","image\\113.jpg"};

    Icon[] icons = new Icon[iconFiles.length];

    public QQZC(){

        super("注册界面");

        setLayout(null);

        box = new ImageIcon("image\\00.jpg");      

        label = new JLabel(box);

        label.setBounds(0,0,440,50);

        add(label);

        label=new JLabel("昵称:");

        label.setBounds(50,80, 40,25);

        add(label);

        nic =new JTextField(12);

        nic.setBounds(100,80,150,22);

        add(nic);

        label=new JLabel("密码:");

        label.setBounds(180,110,40,25);

        add(label);

        mima =new JPasswordField(18);

        mima.setBounds(230, 110, 150, 22);

        add(mima);

        label = new JLabel("性别:");

        label.setBounds(50,140,60,25);

        add(label);

        bold = new JRadioButton( "男");

        bold.setBounds(100, 130, 40, 22);

        add(bold);

        vertical = new JRadioButton( "女");

        vertical.setBounds(150, 140, 40, 22);

        add(vertical);

        vertical1 = new JRadioButton( "保密");

        vertical1.setBounds(200, 150, 60, 22);

        add(vertical1);

        ButtonGroup b=new ButtonGroup();

        b.add(bold);

        b.add(vertical);

        b.add(vertical1);

        label=new JLabel("年龄:");

        label.setBounds(50,190,40,25);

        add(label);

        nl =new JTextField(18);

        nl.setBounds(50, 220, 150, 22);

        add(nl);

        label=new JLabel("生日:");

        label.setBounds(50,250, 40,25);

        add(label);

        sr =new JTextField(6);

        sr.setBounds(50,280, 150, 22);

        add(sr);

        label=new JLabel("地址:");

        label.setBounds(50,310, 40,25);

        add(label);

        dizhi =new JTextField();

        dizhi.setBounds(50, 340, 150, 22);

        add(dizhi);

        button = new JLabel("头像:");

        button.setBounds(300,200,60,30);

        add(button);

        for(int i=0;i

            icons[i]=new ImageIcon(iconFiles[i]);

        }

        iconsBox=new JComboBox(icons);

        iconsBox.setBounds(250,250,70,80);

        add(iconsBox);

        labelq=new JButton("确定:");

        labelq.setForeground(Color.RED);    //给字加颜色!!

        labelq.setBounds(100,400,80,30);

        add(labelq);

        labelt=new JButton("退出:");

        labelt.setForeground(Color.RED);    //给字加颜色!!

        labelt.setBounds(250,400,80,30);

        add(labelt);

        box1 = new ImageIcon("image\\1.jpg");      

        label = new JLabel(box1);

        label.setBounds(0,0,440,460);

        add(label);

        monitor m=new monitor();

        labelq.addActionListener(m);

        labelt.addActionListener(m);

        setSize(455, 500);

        setLocation(100,100);//出来时的位置!

        setVisible(true);

        setAlwaysOnTop(true);

        setResizable(false);

        setIconImage(Toolkit.getDefaultToolkit().getImage("image\\123.jpg"));

        addWindowListener(new WindowAdapter(){

            public void windowClosing(WindowEvent arg0){

                QQZC.this.dispose();

            }

        });

    }

    class monitor implements ActionListener{

        public void actionPerformed(ActionEvent a) {

            String s="";

            if(a.getSource()==labelq){

                if(bold.isSelected()){

                    s="男";

                }else if(vertical.isSelected()){

                    s="女";

                }else if(vertical1.isSelected()){

                    s="保密";

                }

                int SelectedIndex = iconsBox.getSelectedIndex();

                String str = iconFiles[SelectedIndex];

//              User u = new User();

//              u.setName(nic.getText());

//              u.setPassword(mima.getText());

//              u.setAge(nl.getText());

//              u.setSex(s);

//              u.setBirthday(sr.getText());

//              u.setAddr(dizhi.getText());

//              u.setIconNum(str);

//              UserDao dao=new UserDao();

//              dao.insert(u);

                JOptionPane.showMessageDialog(QQZC.this,"昵称:"+nic.getText()+"\n性别:"+s+"\n年龄:"+nl.getText()+"\n生日:"+sr.getText()+"\n地址:"+dizhi.getText()+

                        "\n头像:"+icons[iconsBox.getSelectedIndex()]);//当没有指定位置的时候为null、、指定在那个位置就在这个位置后加.this!

                JOptionPane.showMessageDialog(QQZC.this,"你拥有了自己的扣扣、现在就去登入吧");

//              new QQDR();

                setVisible(false);

            }

            else if(a.getSource()==labelt){

                System.exit(0);

            }

        }

    }

    public static void main(String[] args) {

        new QQZC();

    }

}

一个用JAVA做网页的小程序

<html>

<script type="text/javascript">

function change(){

var color = document.getElementById("color").value;

var div = document.getElementById("text");

if (color)

div.style.color = color;

}

</script>

<body>

<div id="text">今天你学JAVA了吗</div>

<input type="textfield" id="color" />

<input type="button" onclick="change();" value="确定"/>

</body>

</html>