首页编程java编程java代码可复制免费,冒泡排序java代码

java代码可复制免费,冒泡排序java代码

编程之家2026-05-24814次浏览

大家好,java代码可复制免费相信很多的网友都不是很明白,包括冒泡排序java代码也是一样,不过没有关系,接下来就来为大家分享关于java代码可复制免费和冒泡排序java代码的一些知识点,大家可以关注收藏,免得下次来找不到哦,下面我们开始吧!

java代码可复制免费,冒泡排序java代码

利用java编写代码实现如下功能,需要全部代码

很简单的应用,为了节省字数,代码注释我就不加了

首先是显示层,LoinWindow:

importjava.awt.FlowLayout;

importjava.awt.GridBagConstraints;

importjava.awt.GridBagLayout;

importjava.awt.GridLayout;

java代码可复制免费,冒泡排序java代码

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjava.awt.event.FocusEvent;

importjava.awt.event.FocusListener;

importjavax.swing.JButton;

importjavax.swing.JFrame;

java代码可复制免费,冒泡排序java代码

importjavax.swing.JLabel;

importjavax.swing.JOptionPane;

importjavax.swing.JPanel;

importjavax.swing.JTextField;

importjavax.swing.border.EmptyBorder;

publicclassLoinWindowextendsJFrameimplementsActionListener,FocusListener{

privateJPanelmainPanel,namePanel,btnPanel;

privateJTextFieldtfName,tfPsd;

privateJButtonbtnLogin,btnCancel;

privatestaticfinalintWIDTH=300;

privatestaticfinalintHEIGHT=200;

privateLoginServiceservice=newLoginService();

publicLoinWindow(){

super("登录窗体");

}

publicvoidlaunch(){

setSize(WIDTH,HEIGHT);

setVisible(true);

setDefaultCloseOperation(EXIT_ON_CLOSE);

GridLayoutmainLayout=newGridLayout(2,1);

mainLayout.setVgap(10);

mainPanel=newJPanel(mainLayout);

GridBagLayoutnameLayout=newGridBagLayout();

namePanel=newJPanel(nameLayout);

namePanel.setBorder(newEmptyBorder(10,10,10,10));

JLabelnameLabel=newJLabel("姓名:");

tfName=newJTextField();

JLabelpsdLabel=newJLabel("密码:");

tfPsd=newJTextField();

JLabelblank=newJLabel("");

namePanel.add(nameLabel);

namePanel.add(tfName);

namePanel.add(blank);

namePanel.add(psdLabel);

namePanel.add(tfPsd);

GridBagConstraintss=newGridBagConstraints();

s.fill=GridBagConstraints.BOTH;

s.gridwidth=1;

s.weightx=0;

s.weighty=0;

nameLayout.setConstraints(nameLabel,s);

s.gridwidth=0;

s.weightx=1;

s.weighty=0;

nameLayout.setConstraints(tfName,s);

s.gridwidth=0;

s.weightx=4;

s.weighty=0;

nameLayout.setConstraints(blank,s);

s.gridwidth=1;

s.weightx=0;

s.weighty=0;

nameLayout.setConstraints(psdLabel,s);

s.gridwidth=3;

s.weightx=1;

s.weighty=0;

nameLayout.setConstraints(tfPsd,s);

FlowLayoutbtnLayout=newFlowLayout();

btnLayout.setAlignment(FlowLayout.CENTER);

btnPanel=newJPanel(btnLayout);

btnLogin=newJButton("确定");

btnCancel=newJButton("取消");

btnPanel.add(btnLogin);

btnPanel.add(btnCancel);

btnCancel.addActionListener(this);

btnLogin.addActionListener(this);

mainPanel.add(namePanel);

mainPanel.add(btnPanel);

setContentPane(mainPanel);

tfName.addFocusListener(this);

tfPsd.addFocusListener(this);

pack();

setSize(WIDTH,HEIGHT);

setLocationRelativeTo(null);

}

@Override

publicvoidactionPerformed(ActionEvente){

Objectsource=e.getSource();

if(source==btnCancel){

System.exit(0);

}elseif(source==btnLogin){

Stringusername=tfName.getText();

Stringpassword=tfPsd.getText();

booleansuccess=service.login(username,password);

if(success){

warn("成功","登录成功!");

}else{

warn("失败","您输入的用户名或密码错误!");

}

}

}

@Override

publicvoidfocusGained(FocusEventarg0){

}

@Override

publicvoidfocusLost(FocusEvente){

Objectsource=e.getSource();

if(source==tfName){

Stringusername=tfName.getText();

try{

service.matchUsername(username);

}catch(LoginExceptione1){

warn("验证错误",e1.getMessage());

}

}elseif(source==tfPsd){

Stringpassword=tfPsd.getText();

try{

service.matchPassword(password);

}catch(LoginExceptione1){

warn("验证错误",e1.getMessage());

}

}

}

privatevoidwarn(Stringtitle,Stringmsg){

JOptionPane.showMessageDialog(null,msg,title,JOptionPane.INFORMATION_MESSAGE);

}

publicstaticvoidmain(String[]args){

newLoinWindow().launch();

}

}然后是模型层:LoginDao

publicclassLoginDao{

publicbooleanlogin(Stringusername,Stringpassword){

if(username.equals("admin")&&password.equals("12345")){

returntrue;

}

returnfalse;

}

}LoginService

importjava.util.regex.Pattern;

publicclassLoginService{

privatestaticfinalPatternLOGIN_PATTERN=Pattern.compile("[a-zA-Z]+");

privatestaticfinalPatternPASSWORD_PATTERN=Pattern.compile("[1-9]+");

privateLoginDaodao=newLoginDao();

publicbooleanmatchUsername(Stringusername)throwsLoginException{

if(null==username||username.isEmpty()){

returnfalse;

}

if(!LOGIN_PATTERN.matcher(username).matches()){

thrownewLoginException("您输入的用户名不合法,请输入英文!");

}

returntrue;

}

publicbooleanmatchPassword(Stringpassword)throwsLoginException{

if(null==password||password.isEmpty()){

returnfalse;

}

if(!PASSWORD_PATTERN.matcher(password).matches()){

thrownewLoginException("您输入的密码不合法,请输入数字!");

}

returntrue;

}

publicbooleanlogin(Stringusername,Stringpassword){

if(null==username||username.isEmpty()){

returnfalse;

}

if(null==password||password.isEmpty()){

returnfalse;

}

if(!dao.login(username,password)){

returnfalse;

}

returntrue;

}

}LoginException

publicclassLoginExceptionextendsException{

publicLoginException(Stringarg0){

super(arg0);

}

}不知道分层设计思想是不是我想的这样

急求一段简单的java源代码(用户名、密码操作界面)

下面的程序可以直接通过编译运行,自己寻找要用到的代码段。

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.FocusEvent;

import java.awt.event.FocusListener;

import java.io.File;

import java.io.IOException;

import java.io.RandomAccessFile;

import javax.swing.BoxLayout;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

public class UserLogin extends JPanel implements ActionListener{

JTextField userjt=null;//用户输入框

JPasswordField pwdjt=null;

JTextField sysUserjt=null;//系统显示用户名输入框

JTextField sysPwdjt=null;

public UserLogin(){

super(new GridLayout(1,2));

JPanel userPanel=new JPanel();//用户界面,左边

userPanel.setLayout(new BoxLayout(userPanel,BoxLayout.Y_AXIS));

this.add(userPanel);

JPanel userUpPanel=new JPanel();//用户界面上半部分

userPanel.add(userUpPanel);

JPanel userDownPanel=new JPanel();//用户界面下半部分

userPanel.add(userDownPanel);

JPanel sysPanel=new JPanel();//系统界面,右边

sysPanel.setLayout(new BoxLayout(sysPanel,BoxLayout.Y_AXIS));

this.add(sysPanel);

JPanel sysUserPanel=new JPanel();//系统界面上半部分

sysPanel.add(sysUserPanel);

JPanel sysPwdPanel=new JPanel();//系统界面下半部分

sysPanel.add(sysPwdPanel);

userjt=new JTextField(5);

userjt.setText("用户名");

userUpPanel.add(userjt);

pwdjt=new JPasswordField(5);

pwdjt.setText("密码");

pwdjt.setEchoChar('\0');

userDownPanel.add(pwdjt);

JLabel sysUserjl=new JLabel("用户名为:");

sysUserPanel.add(sysUserjl);

sysUserjt=new JTextField(5);

sysUserPanel.add(sysUserjt);

JLabel sysPwdjl=new JLabel("密码为:");

sysPwdPanel.add(sysPwdjl);

sysPwdjt=new JTextField(5);

sysPwdPanel.add(sysPwdjt);

userjt.addActionListener(this);

pwdjt.addActionListener(this);

userjt.addFocusListener(new FocusListener(){

public void focusGained(FocusEvent e){

if(userjt.getText().equals("用户名"))

userjt.setText("");

}

public void focusLost(FocusEvent e){

if(userjt.getText().equals(""))

userjt.setText("用户名");

}});

pwdjt.addFocusListener(new FocusListener(){

public void focusGained(FocusEvent e){

if(new String(pwdjt.getPassword()).equals("密码")){

pwdjt.setText("");

pwdjt.setEchoChar('*');

}

}

public void focusLost(FocusEvent e){

if(new String(pwdjt.getPassword()).equals("")){

pwdjt.setText("密码");

pwdjt.setEchoChar('\0');

}

}});

}

public void actionPerformed(ActionEvent e){

if(e.getSource().equals(userjt)){

pwdjt.requestFocus();

}else{

if(new String(pwdjt.getPassword()).equals("")||userjt.getText().equals("")||userjt.getText().equals("用户名")) return;

sysUserjt.setText(userjt.getText());

sysPwdjt.setText(new String(pwdjt.getPassword()));

try{

writetoFile();

} catch(IOException e1){

System.out.println("写入文件发生异常!");

e1.printStackTrace();

}

}

}

private void writetoFile() throws IOException{

File f=new File("User_Psd.txt");

// if(!f.exists()) f.createNewFile();

RandomAccessFile accessFile=new RandomAccessFile(f,"rw");

accessFile.seek(accessFile.length());

accessFile.write(("user:"+userjt.getText()+"\r\npassword:"+new String(pwdjt.getPassword())+"\r\n\r\n").getBytes());

}

public static void main(String args[]){

JFrame jf=new JFrame("用户登陆模块测试");

jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);

jf.add(new UserLogin());

jf.setBounds(400,300,280,150);

jf.setVisible(true);

}

}

求一个简单java程序代码,谢谢

刚开始java的时候用记事本编写java源代码,在命令提示符中完成java程序的编译和运行过程,这样是为了更好的理解java基础。

以后可以用Eclipse或其他的开发环境。eclipse有自己的编译器ECJ,会自动进行编译,编写、编译、运行等都可以在一个平台上完成。这样就不用借助cmd手动编译Java程序了。

好了,文章到这里就结束啦,如果本次分享的java代码可复制免费和冒泡排序java代码问题对您有所帮助,还望关注下本站哦!

数据库系统的特点有哪些?用于存放数据库数据的是盗贼开锁技能(盗贼怎么练开锁技能)