资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Java源代码人形状,JAVA登录页面制作源代码

JAVA源程序代码

您好,写了一个程序,求素数,并将所有素数存到ArrayList sushu中:

在垦利等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站制作、做网站 网站设计制作按需求定制网站,公司网站建设,企业网站建设,高端网站设计,成都全网营销推广,成都外贸网站建设公司,垦利网站建设费用合理。

import java.util.ArrayList;

import java.util.zip.Inflater;

public class sushu {

public static void main(String[] args) {

int n=50,b=0;

float a=0,c=0;

ArrayList sushu=new ArrayList();

for(int i=3;i=n;i++){

int state=0;

for(int j=2;j(i/2+1);j++){

a=(float)i/(float)j;

//System.out.println(a);

b=(int)a;

//System.out.println(a-b);

c=a-b;

//System.out.println(c);

if(c==0){state=1;break;}

}

if(state==0)sushu.add(i);

}

System.out.println(sushu);

}

}

输出结果为:[3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]

求java版画图程序的源代码

找到了,很久以前写的一个简单画图,呵呵~当时要求用AWT写,很难受。

package net.miqiang.gui;

import java.awt.BasicStroke;

import java.awt.BorderLayout;

import java.awt.Button;

import java.awt.Color;

import java.awt.Cursor;

import java.awt.Dimension;

import java.awt.Frame;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.GridLayout;

import java.awt.Label;

import java.awt.Panel;

import java.awt.RenderingHints;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.awt.event.MouseMotionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.awt.image.BufferedImage;

/**

* 简单画图板程序

* 好久没用 AWT 了,写起来真别扭,如果用 swing 会很舒服,有空再改写吧。

*

* @author 米强

*

*/

public class TestMain extends Frame {

// 画板

private Palette palette = null;

// 显示当前颜色的面板

private Panel nonceColor = null;

// 画笔粗细

private Label drawWidth = null;

// 画笔端点的装饰

private Label drawCap = null;

// 选取颜色按钮的监听事件类

private ButtonColorAction buttonColorAction = null;

// 鼠标进入按钮后光标样式的监听事件类

private ButtonCursor buttonCursor = null;

// 画笔样式的监听事件

private ButtonStrokeAction buttonStrokeAction = null;

/**

* 构造方法

*

*/

public TestMain() {

// 设置标题栏文字

super("简易画图板");

// 构造一个画图板

palette = new Palette();

Panel pane = new Panel(new GridLayout(2, 1));

// 画笔颜色选择器

Panel paneColor = new Panel(new GridLayout(1, 13));

// 12 个颜色选择按钮

Button [] buttonColor = new Button[12];

Color [] color = {Color.black, Color.blue, Color.cyan, Color.darkGray, Color.gray, Color.green, Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow};

// 显示当前颜色的面板

nonceColor = new Panel();

nonceColor.setBackground(Color.black);

paneColor.add(nonceColor);

buttonColorAction = new ButtonColorAction();

buttonCursor = new ButtonCursor();

for(int i = 0; i buttonColor.length; i++){

buttonColor[i] = new Button();

buttonColor[i].setBackground(color[i]);

buttonColor[i].addActionListener(buttonColorAction);

buttonColor[i].addMouseListener(buttonCursor);

paneColor.add(buttonColor[i]);

}

pane.add(paneColor);

// 画笔颜色选择器

Panel paneStroke = new Panel(new GridLayout(1, 13));

// 控制画笔样式

buttonStrokeAction = new ButtonStrokeAction();

Button [] buttonStroke = new Button[11];

buttonStroke[0] = new Button("1");

buttonStroke[1] = new Button("3");

buttonStroke[2] = new Button("5");

buttonStroke[3] = new Button("7");

buttonStroke[4] = new Button("9");

buttonStroke[5] = new Button("11");

buttonStroke[6] = new Button("13");

buttonStroke[7] = new Button("15");

buttonStroke[8] = new Button("17");

buttonStroke[9] = new Button("■");

buttonStroke[10] = new Button("●");

drawWidth = new Label("3", Label.CENTER);

drawCap = new Label("●", Label.CENTER);

drawWidth.setBackground(Color.lightGray);

drawCap.setBackground(Color.lightGray);

paneStroke.add(drawWidth);

for(int i = 0; i buttonStroke.length; i++){

paneStroke.add(buttonStroke[i]);

buttonStroke[i].addMouseListener(buttonCursor);

buttonStroke[i].addActionListener(buttonStrokeAction);

if(i = 8){

buttonStroke[i].setName("width");

}else{

buttonStroke[i].setName("cap");

}

if(i == 8){

paneStroke.add(drawCap);

}

}

pane.add(paneStroke);

// 将画笔颜色选择器添加到窗体中

this.add(pane, BorderLayout.NORTH);

// 将画图板添加到窗体中

this.add(palette);

// 添加窗口监听,点击关闭按钮时退出程序

this.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

// 设置窗体 ICON 图标

this.setIconImage(Toolkit.getDefaultToolkit().createImage("images/palette.png"));

// 设置窗口的大小

this.setSize(new Dimension(400, 430));

// 设置窗口位置,处于屏幕正中央

this.setLocationRelativeTo(null);

// 显示窗口

this.setVisible(true);

}

/**

* 程序入口

*

* @param args

* 字符串数组参数

*/

public static void main(String[] args) {

new TestMain();

}

/**

* 选取颜色按钮的监听事件类

* @author 米强

*

*/

class ButtonColorAction implements ActionListener {

public void actionPerformed(ActionEvent e) {

Color color_temp = ((Button)e.getSource()).getBackground();

nonceColor.setBackground(color_temp);

palette.setColor(color_temp);

}

}

/**

* 鼠标进入按钮变换光标样式监听事件类

* @author 米强

*

*/

class ButtonCursor extends MouseAdapter {

public void mouseEntered(MouseEvent e) {

((Button)e.getSource()).setCursor(new Cursor(Cursor.HAND_CURSOR));

}

public void mouseExited(MouseEvent e) {

((Button)e.getSource()).setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

}

}

/**

* 设置画笔的监听事件类

* @author 米强

*

*/

class ButtonStrokeAction implements ActionListener {

public void actionPerformed(ActionEvent e) {

Button button_temp = (Button) e.getSource();

String name = button_temp.getName();

if(name.equalsIgnoreCase("width")){

drawWidth.setText(button_temp.getLabel());

palette.setStroke(Float.parseFloat(button_temp.getLabel()));

}else if(name.equalsIgnoreCase("cap")){

drawCap.setText(button_temp.getLabel());

if(button_temp.getLabel().equals("■")){

palette.setStroke(BasicStroke.CAP_SQUARE);

}else if(button_temp.getLabel().equals("●")){

palette.setStroke(BasicStroke.CAP_ROUND);

}

}

}

}

}

/**

* 画板类

*

* @author 米强

*

*/

class Palette extends Panel implements MouseListener, MouseMotionListener {

// 鼠标 X 坐标的位置

private int mouseX = 0;

// 上一次 X 坐标位置

private int oldMouseX = 0;

// 鼠标 Y 坐标的位置

private int mouseY = 0;

// 上一次 Y 坐标位置

private int oldMouseY = 0;

// 画图颜色

private Color color = null;

// 画笔样式

private BasicStroke stroke = null;

// 缓存图形

private BufferedImage image = null;

/**

* 构造一个画板类

*

*/

public Palette() {

this.addMouseListener(this);

this.addMouseMotionListener(this);

// 默认黑色画笔

color = new Color(0, 0, 0);

// 设置默认画笔样式

stroke = new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);

// 建立 1280 * 1024 的 RGB 缓存图象

image = new BufferedImage(1280, 1024, BufferedImage.TYPE_INT_RGB);

// 设置颜色

image.getGraphics().setColor(Color.white);

// 画背景

image.getGraphics().fillRect(0, 0, 1280, 1024);

}

/**

* 重写 paint 绘图方法

*/

public void paint(Graphics g) {

super.paint(g);

// 转换为 Graphics2D

Graphics2D g2d = (Graphics2D) g;

// 获取缓存图形 Graphics2D

Graphics2D bg = image.createGraphics();

// 图形抗锯齿

bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

// 设置绘图颜色

bg.setColor(color);

// 设置画笔样式

bg.setStroke(stroke);

// 画线,从上一个点到新的点

bg.drawLine(oldMouseX, oldMouseY, mouseX, mouseY);

// 将缓存中的图形画到画板上

g2d.drawImage(image, 0, 0, this);

}

/**

* 重写 update 方法

*/

public void update(Graphics g) {

this.paint(g);

}

/**

* @return stroke

*/

public BasicStroke getStroke() {

return stroke;

}

/**

* @param stroke 要设置的 stroke

*/

public void setStroke(BasicStroke stroke) {

this.stroke = stroke;

}

/**

* 设置画笔粗细

* @param width

*/

public void setStroke(float width) {

this.stroke = new BasicStroke(width, stroke.getEndCap(), stroke.getLineJoin());

}

/**

* 设置画笔端点的装饰

* @param cap 参考 java.awt.BasicStroke 类静态字段

*/

public void setStroke(int cap) {

this.stroke = new BasicStroke(stroke.getLineWidth(), cap, stroke.getLineJoin());

}

/**

* @return color

*/

public Color getColor() {

return color;

}

/**

* @param color 要设置的 color

*/

public void setColor(Color color) {

this.color = color;

}

public void mouseClicked(MouseEvent mouseEvent) {

}

/**

* 鼠标按下

*/

public void mousePressed(MouseEvent mouseEvent) {

this.oldMouseX = this.mouseX = mouseEvent.getX();

this.oldMouseY = this.mouseY = mouseEvent.getY();

repaint();

}

public void mouseReleased(MouseEvent mouseEvent) {

}

/**

* 鼠标进入棋盘

*/

public void mouseEntered(MouseEvent mouseEvent) {

this.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));

}

/**

* 鼠标退出棋盘

*/

public void mouseExited(MouseEvent mouseEvent) {

this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

}

/**

* 鼠标拖动

*/

public void mouseDragged(MouseEvent mouseEvent) {

this.oldMouseX = this.mouseX;

this.oldMouseY = this.mouseY;

this.mouseX = mouseEvent.getX();

this.mouseY = mouseEvent.getY();

repaint();

}

public void mouseMoved(MouseEvent mouseEvent) {

}

}

java简单记事本源代码 带解释

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;

class test implements ActionListener

{

JFrame frame;

JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30,b31;

JTextArea ta;

JPanel p1,p2,p3,p4;

JMenuBar mb;

JMenu m1,m2,m3;

JMenuItem mt1,mt2,mt3,mt4,mt5,mt6,mt7;

JRadioButton rb1,rb2;

ButtonGroup bg;

Double d1=0.0,d2=0.0,d3=0.0,d4=1.0,d5=1.0;

String s1="",s2="",s3="",s4="";

int a=0;

char c1;

int i=0;

public static void main(String[] args)

{

test that=new test();

that.go();

}

public void go()

{

frame=new JFrame("计算器");

Container cp= frame.getContentPane();

cp.setLayout(new FlowLayout());

b1=new JButton("7");b2=new JButton("8");b3=new JButton("9");b4=new JButton("/");b5=new JButton("1/x");b6=new JButton("sin");b7=new JButton("log");

b8=new JButton("4");b9=new JButton("5");b10=new JButton("6");b11=new JButton("*");b12=new JButton("x^y");b13=new JButton("cos");b14=new JButton("ln");

b15=new JButton("1");b16=new JButton("2");b17=new JButton("3");b18=new JButton("-");b19=new JButton(new ImageIcon("lanying.gif"));b20=new JButton("tan");b21=new JButton("x^3");

b22=new JButton("0");b23=new JButton("+/-");b24=new JButton(".");b25=new JButton("+");b26=new JButton("√x");b27=new JButton("cot");b28=new JButton("x^2");

b29=new JButton("Backspace");b30=new JButton("C");b31=new JButton("=");

mb=new JMenuBar();

m1=new JMenu("文件(F)");m2=new JMenu("编辑(E)");m3=new JMenu("帮助(H)");

mt1=new JMenuItem("清零");mt2=new JMenuItem("退出");mt3=new JMenuItem("复制");mt4=new JMenuItem("粘贴");mt5=new JMenuItem("版本");mt6=new JMenuItem("标准型");mt7=new JMenuItem("科学型");

ta=new JTextArea(1,30);

p1=new JPanel();p2=new JPanel();p3=new JPanel();p4=new JPanel();

rb1=new JRadioButton("科学型");rb2=new JRadioButton("标准型");

bg=new ButtonGroup();

b1.setForeground(Color.blue);b1.setBackground(Color.white);b2.setForeground(Color.blue);b2.setBackground(Color.white);

b3.setForeground(Color.blue);b3.setBackground(Color.white);b8.setForeground(Color.blue);b8.setBackground(Color.white);

b9.setForeground(Color.blue);b9.setBackground(Color.white);b10.setForeground(Color.blue);b10.setBackground(Color.white);

b15.setForeground(Color.blue);b15.setBackground(Color.white);b16.setForeground(Color.blue);b16.setBackground(Color.white);

b17.setForeground(Color.blue);b17.setBackground(Color.white);b22.setForeground(Color.blue);b22.setBackground(Color.white);

b23.setForeground(Color.blue);b23.setBackground(Color.white);b24.setForeground(Color.blue);b24.setBackground(Color.white);

b4.setForeground(Color.red);b4.setBackground(Color.white);b11.setForeground(Color.red);b11.setBackground(Color.white);

b18.setForeground(Color.red);b18.setBackground(Color.white);b25.setForeground(Color.red);b25.setBackground(Color.white);

b5.setForeground(Color.blue);b5.setBackground(Color.white);b6.setForeground(Color.blue);b6.setBackground(Color.white);

b7.setForeground(Color.blue);b7.setBackground(Color.white);b12.setForeground(Color.blue);b12.setBackground(Color.white);

b13.setForeground(Color.blue);b13.setBackground(Color.white);b14.setForeground(Color.blue);b14.setBackground(Color.white);

b19.setForeground(Color.blue);b19.setBackground(Color.white);b20.setForeground(Color.blue);b20.setBackground(Color.white);

b21.setForeground(Color.blue);b21.setBackground(Color.white);b26.setForeground(Color.blue);b26.setBackground(Color.white);

b27.setForeground(Color.blue);b27.setBackground(Color.white);b28.setForeground(Color.blue);b28.setBackground(Color.white);

b29.setForeground(Color.red);b29.setBackground(Color.white);b30.setForeground(Color.red);b30.setBackground(Color.white);

b31.setForeground(Color.red);b31.setBackground(Color.white);

bg.add(rb1);bg.add(rb2);

p1.setBackground(Color.yellow);

cp.setBackground(Color.CYAN);

m1.setMnemonic(KeyEvent.VK_F);m2.setMnemonic(KeyEvent.VK_E);m3.setMnemonic(KeyEvent.VK_H);

m1.add(mt6);m1.add(mt7);m1.addSeparator();m1.add(mt1);m1.addSeparator();m1.add(mt2);m2.add(mt3);m2.addSeparator();m2.add(mt4);m3.add(mt5);

mb.add(m1);mb.add(m2);mb.add(m3);

frame.setJMenuBar(mb);

p2.setLayout(new GridLayout(4,7));

p3.setLayout(new GridLayout(1,3));

ta.setEditable(false);

p1.add(ta);

p2.add(b1);p2.add(b2);p2.add(b3);p2.add(b4);p2.add(b5);p2.add(b6);p2.add(b7);

p2.add(b8);p2.add(b9);p2.add(b10);p2.add(b11);p2.add(b12);p2.add(b13);p2.add(b14);

p2.add(b15);p2.add(b16);p2.add(b17);p2.add(b18);p2.add(b19);p2.add(b20);p2.add(b21);

p2.add(b22);p2.add(b23);p2.add(b24);p2.add(b25);p2.add(b26);p2.add(b27);p2.add(b28);

p3.add(b29);p3.add(b30);p3.add(b31);

Border etched=BorderFactory.createEtchedBorder();

Border border=BorderFactory.createTitledBorder(etched,"计算类型");

p4.add(rb1);p4.add(rb2);

p4.setBorder(border);

b2.setActionCommand("8");

b2.addActionListener(this);

cp.add(p1);cp.add(p4);cp.add(p2);cp.add(p3);

frame.setSize(400,330);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

b1.setActionCommand("7");

b1.addActionListener(this);

b2.setActionCommand("8");

b2.addActionListener(this);

b3.setActionCommand("9");

b3.addActionListener(this);

b4.setActionCommand("/");

b4.addActionListener(this);

b5.setActionCommand("1/x");

b5.addActionListener(this);

b6.setActionCommand("sin");

b6.addActionListener(this);

b7.setActionCommand("log");

b7.addActionListener(this);

b8.setActionCommand("4");

b8.addActionListener(this);

b9.setActionCommand("5");

b9.addActionListener(this);

b10.setActionCommand("6");

b10.addActionListener(this);

b11.setActionCommand("*");

b11.addActionListener(this);

b12.setActionCommand("x^y");

b12.addActionListener(this);

b13.setActionCommand("cos");

b13.addActionListener(this);

b14.setActionCommand("ln");

b14.addActionListener(this);

b15.setActionCommand("1");

b15.addActionListener(this);

b16.setActionCommand("2");

b16.addActionListener(this);

b17.setActionCommand("3");

b17.addActionListener(this);

b18.setActionCommand("-");

b18.addActionListener(this);

b19.setActionCommand("x!");

b19.addActionListener(this);

b20.setActionCommand("tan");

b20.addActionListener(this);

b21.setActionCommand("x^3");

b21.addActionListener(this);

b22.setActionCommand("0");

b22.addActionListener(this);

b23.setActionCommand("+/-");

b23.addActionListener(this);

b24.setActionCommand(".");

b24.addActionListener(this);

b25.setActionCommand("+");

b25.addActionListener(this);

b26.setActionCommand("√x");

b26.addActionListener(this);

b27.setActionCommand("cot");

b27.addActionListener(this);

b28.setActionCommand("x^2");

b28.addActionListener(this);

b29.setActionCommand("Backspace");

b29.addActionListener(this);

b30.setActionCommand("C");

b30.addActionListener(this);

b31.setActionCommand("=");

b31.addActionListener(this);

rb1.setActionCommand("kxx");

rb1.addActionListener(this);

rb2.setActionCommand("bzx");

rb2.addActionListener(this);

}

public void actionPerformed(ActionEvent e) //throws Exception

{

if (e.getActionCommand()=="bzx")

{

b5.setEnabled(false);b6.setEnabled(false);b7.setEnabled(false);

b12.setEnabled(false);b13.setEnabled(false);b14.setEnabled(false);

b19.setEnabled(false);b20.setEnabled(false);b21.setEnabled(false);

b26.setEnabled(false);b27.setEnabled(false);b28.setEnabled(false);

}

if (e.getActionCommand()=="kxx")

{

b5.setEnabled(true);b6.setEnabled(true);b7.setEnabled(true);

b12.setEnabled(true);b13.setEnabled(true);b14.setEnabled(true);

b19.setEnabled(true);b20.setEnabled(true);b21.setEnabled(true);

b26.setEnabled(true);b27.setEnabled(true);b28.setEnabled(true);

}

if (e.getActionCommand()=="1")

{

ta.append("1");

}

if (e.getActionCommand()=="2")

{

ta.append("2");

}

if (e.getActionCommand()=="3")

{

ta.append("3");

}

if (e.getActionCommand()=="4")

{

ta.append("4");

}

if (e.getActionCommand()=="5")

{

ta.append("5");

}

if (e.getActionCommand()=="6")

{

ta.append("6");

}

if (e.getActionCommand()=="7")

{

ta.append("7");

}

if (e.getActionCommand()=="8")

{

ta.append("8");

}

if (e.getActionCommand()=="9")

{

ta.append("9");

}

if (e.getActionCommand()=="0")

{

ta.append("0");

}

if (e.getActionCommand()=="+")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=1;

}

if (e.getActionCommand()=="-")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=2;

}

if (e.getActionCommand()=="*")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=3;

}

if (e.getActionCommand()=="/")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=4;

}

if (e.getActionCommand()=="=")

{

s2=ta.getText();

d2=Double.parseDouble(s2);

if(i==1)

{

d3=d1+d2;

ta.setText( d3.toString());

}

if(i==2)

{

d3=d1-d2;

ta.setText( d3.toString());

}

if(i==3)

{

d3=d1*d2;

ta.setText( d3.toString());

}

if(i==4)

{

if(d2==0.0)

ta.setText("ERROR");

else

{

d3=d1/d2;

ta.setText( d3.toString());

}

}

if (i==5)

{

s2=ta.getText();

d2 = Double.parseDouble(s2);

for (int l=1;l=d2 ; l++)

{

d5=d5*d1;

}

ta.setText( d5.toString());

}

}

if (e.getActionCommand()=="C")

{

ta.setText("");

d4=1.0;

d5=1.0;

}

/*if (e.getActionCommand()=="Backspace")

{

s3=ta.getText();

a=s3.length();

//ta.cut(ta.select(a-1,a));

s4=ta.getText(1,3);

ta.setText(s4);

}

*/

if (e.getActionCommand()=="1/x")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=1/d1;

ta.setText( d2.toString());

}

if (e.getActionCommand()==".")

{

ta.append(".");

}

if (e.getActionCommand()=="+/-")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=0-d1;

ta.setText( d2.toString());

}

if (e.getActionCommand()=="x^2")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=d1*d1;

ta.setText( d2.toString());

}

if (e.getActionCommand()=="x^3")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=d1*d1*d1;

ta.setText( d2.toString());

}

if (e.getActionCommand()=="x^y")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=5;

// d2=d1*d1*d1;

// ta.setText( d2.toString());

}

if (e.getActionCommand()=="√x")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=Math.sqrt(d1);

ta.setText( d2.toString());

}

if (e.getActionCommand()=="x!")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

if (d10)

{

ta.setText( "error");

}

else if (d1==0)

{

ta.setText( "0.0");

}

else {

for (int k=1;k=d1 ;k++ )

d4=d4*k;

ta.setText( d4.toString());

}

}

if (e.getActionCommand()=="sin")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=Math.sin(3.1415926*d1/180);

ta.setText( d2.toString());

}

}

}

求JAVA源代码

我用了半个小时 帮你写了一个简单的验证用户名和密码登陆问题 别辜负我的好意 下面是代码!(建好包和类 代码粘过去就能用)

实体类 包entity

-------------------------------------------------------------

package entity;

/**

* 用户实体类

* @author new

*

*/

public class Users {

private String name;//用户名

private String pass;//用户密码

/**

* 空的构造函数 用户实力化 此类对象

*/

public Users(){

}

/**

* 构造函数 接收用户名和密码

* @param name

* @param pass

*/

public Users(String name, String pass) {

this.name = name;

this.pass = pass;

}

/**

* 下面set和get方法就不用解释了吧

* @return

*/

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getPass() {

return pass;

}

public void setPass(String pass) {

this.pass = pass;

}

}

数据库类 包dao(我是模拟一下数据库 没有用到数据库)

--------------------------------------------------------------

package dao;

import java.util.*;

import entity.Users;//导入实体类

/**

* 模拟数据库 用户DAO

* @author new

*

*/

public class UsersDAO {

private static Users users=new Users();

static

{

users.setName("tom");

users.setPass("jerry");

}

/**

* 根据姓名查找这个用户 (模拟一下数据库)

* @param name

* @return

*/

public Users findUserByName(String name)

{

if(name.equals(this.users.getName()))

{

return this.users;

}

return null;

}

}

业务类 包service (验证用户名和密码)

------------------------------------------------------------

package service;

import dao.UsersDAO;

import entity.Users;

/**

* 验证密码 业务类

* @author new

*

*/

public class validatePass {

//实力化DAO对象

private UsersDAO us=new UsersDAO();

/**

* 验证输入的密码是否正确

* @param name

* @param pass

* @return

*/

public Users validate(String name,String pass)

{

Users user=null;

user=us.findUserByName(name);

//如果不为空 说明查到了

if(user!=null)

{

//用查询出来对象的密码和传过来的密码比较

if(user.getPass().equals(pass))

{

return user;

}

}

return null;

}

}

最后是测试test类 包test

----------------------------------------------------------

package test;

import entity.Users;

import service.validatePass;

/**

* 测试类

* @author new

*

*/

public class test {

/**

* main方法 用于测试

* @param args

*/

public static void main(String[] args)

{

//实例化业务类对象

validatePass v=new validatePass();

//用户名和密码

String name="tom";

String pass="jerry";

//开始验证

Users user=v.validate(name, pass);

if(user==null)

{

System.out.println("你输入的用户名或密码错误!");

}else

{

System.out.println("你已经通过验证,成功登陆!");

}

}

}

求java绘图程序源代码(加注释),在如下图的基础上,在图案种类上添加圆角矩形,求代码

直线 是 Line2D

矩形是 Rectangle2D

弧 Arc2D

椭圆 Ellipse2D

圆角矩形是 RoundRectangle2D

上面的都在 java.awt.geom包里

Java里的字节码和源代码分别啥意思,和起到什么左右

/*java是一门高级编程语言,是用来写程序代码的。

用java写的文本(字符串序列)就是源代码。

计算机不能直接执行源代码,必须用一个叫编译器的程序(javac.exe)将源代码

翻译成字节码,然后让一个叫解释器的程序(java.exe)去执行字节码,即运行程序。

下面的就是一个小程序的源代码,功能是输出九九乘法表。

下图中的Test.class就是这个源代码文件翻译后的由字节码组成的文件。

而最下面的那个黑框就是程序执行后的结果。

java Test就是在执行Test.class字节码文件,即运行这个程序。

*/

//这下面的就是源代码

public class Test {

public static void main(String[] args) {

int i,j;

for(i=1;i=9;i++) {

for(j=1;j=i;j++)

System.out.printf("%dx%d=%-4d",j,i,j*i);

System.out.println();

}

}

}


标题名称:Java源代码人形状,JAVA登录页面制作源代码
网址分享:http://cdkjz.cn/article/phcgce.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220