java实现功能代码 java编写代码

Java 要实现此功能 代码应该如何修改?Connection conn;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:taian", "hr", "hr"); //连接Oracle
conn.setAutoCommit(false);
Statement myStat = conn.createStatement();
String sqlTxt = "update BankAccount set account=account-"this.amount.getText()" where accId="this.payOut.getText();
System.out.println("第一步 执行:"sqlTxt);
//
try {
int affectedRow = myStat.executeUpdate(sqlTxt);
System.out.println("从汇出方扣减"this.amount.getText()"元,修改java实现功能代码了"affectedRow"行数据.");
sqlTxt = "update BankAccount set account=account "this.amount.getText()" where accId="this.saveIn.getText();
System.out.println("第二步 执行:"sqlTxt);
affectedRow = myStat.executeUpdate(sqlTxt);
System.out.println("从汇入方增加"this.amount.getText()"元,修改java实现功能代码了"affectedRow"行数据.");
// 事务成功结束, 提交
conn.commit();
} catch (SQLException sqlEx) {
System.out.println
sqlEx.printStackTrace();
// 事务中断,整体回滚到事务开始前状态
conn.rollback();
}
myStat.close();
conn.close();
} catch (Exception ex) {
System.out.println("反正是出错了.");
}
}//
java编程,实现以下功能代码如下:
public class App {
public static void main(String[] args) {
String name = "My name is Networkcrazy";
System.out.println("字符串的长度:"name.length());
System.out.println("字符串中的第一个字符:"name.charAt(0));
System.out.println("字符串中的最后一个字符:"name.charAt(name.length() - 1));
System.out.println("字符串中的第一个单词:"name.split(" ")[0]);
System.out.println("字符串中crazy的位置:"name.indexOf("crazy"));
}
}
运行结果:
实现界面登陆,退出功能的java代码怎么写?CS结构系统的退出如下:public void init() {\x0d\x0athis.setTitle("用户登录界面");\x0d\x0athis.add(createCenterPane());\x0d\x0athis.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);\x0d\x0athis.setSize(new Dimension(450, 335));\x0d\x0athis.setLocationRelativeTo(null);\x0d\x0a// this.setVisible(true);\x0d\x0athis.addWindowListener(new WindowAdapter() {\x0d\x0apublic void windowClosing(WindowEvent e) {\x0d\x0aint choose = JOptionPane.showConfirmDialog(null, "是否要退出登录界面?",\x0d\x0a"系统提示:", JOptionPane.YES_NO_OPTION);\x0d\x0aif (choose == JOptionPane.YES_OPTION) {\x0d\x0aSystem.exit(1);\x0d\x0a}\x0d\x0a}\x0d\x0a});\x0d\x0a }其中this为JFrame对象 。BS结构的退出直接用windows.close()方法就行了!
利用java编程编写代码 , 实现如下功能:package example;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
【java实现功能代码 java编写代码】import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
public class demo extends JFrame{
private JMenuBar menu = new JMenuBar();
private JPanel contentPane = new JPanel();
public demo()
{
setTitle("compiler");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setJMenuBar(menu);
//JMenu correct = new JMenu("正确用例");
//JMenu wrong = new JMenu("错误用例");
////JMenuItem WP = wrong.add("语法错误");
//JMenuItem WL = wrong.add("词法错误");
JMenu edit = new JMenu("编辑");
JMenu help= new JMenu("帮助");
JMenu document = new JMenu("文件");
JMenuItem copy = edit.add("复制");
JMenu color = new JMenu("颜色");
JMenuItem p = color.add("前景色");
p.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"该项目正在建设中", "信息",
JOptionPane.INFORMATION_MESSAGE);
}
});
JMenuItem b = color.add("背景色");
b.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"该项目正在建设中", "信息",
JOptionPane.INFORMATION_MESSAGE);
}
});
edit.add(color);
JMenuItem select = edit.add("全选");
menu.add(document);
menu.add(edit);
menu.add(help);
setLocation(400,200);
setSize(300, 300);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
}
public static void main(String[]args)
{
demo browser = new demo();
browser.setVisible(true);
}
}
利用java编写代码实现如下功能,需要全部代码很简单的应用 , 为了节省字数,代码注释我就不加了
首先是显示层,LoinWindow:
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
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 javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
public class LoinWindow extends JFrame implements ActionListener, FocusListener {
private JPanel mainPanel, namePanel, btnPanel;
private JTextField tfName, tfPsd;
private JButton btnLogin, btnCancel;
private static final int WIDTH = 300;
private static final int HEIGHT = 200;
private LoginService service = new LoginService();
public LoinWindow() {
super("登录窗体");
}
public void launch() {
setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
GridLayout mainLayout = new GridLayout(2, 1);
mainLayout.setVgap(10);
mainPanel = new JPanel(mainLayout);
GridBagLayout nameLayout = new GridBagLayout();
namePanel = new JPanel(nameLayout);
namePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
JLabel nameLabel = new JLabel("姓名:");
tfName = new JTextField();
JLabel psdLabel = new JLabel("密码:");
tfPsd = new JTextField();
JLabel blank = new JLabel(" ");
namePanel.add(nameLabel);
namePanel.add(tfName);
namePanel.add(blank);
namePanel.add(psdLabel);
namePanel.add(tfPsd);
GridBagConstraints s = new GridBagConstraints();
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);
FlowLayout btnLayout = new FlowLayout();
btnLayout.setAlignment(FlowLayout.CENTER);
btnPanel = new JPanel(btnLayout);
btnLogin = new JButton("确定");
btnCancel = new JButton("取消");
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
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if(source == btnCancel) {
System.exit(0);
} else if(source == btnLogin) {
String username = tfName.getText();
String password = tfPsd.getText();
boolean success = service.login(username, password);
if(success) {
warn("成功", "登录成功!");
} else {
warn("失败", "您输入的用户名或密码错误 !");
}
}
}
@Override
public void focusGained(FocusEvent arg0) {
}
@Override
public void focusLost(FocusEvent e) {
Object source = e.getSource();
if(source == tfName) {
String username = tfName.getText();
try {
service.matchUsername(username);
} catch (LoginException e1) {
warn("验证错误", e1.getMessage());
}
} else if(source == tfPsd) {
String password = tfPsd.getText();
try {
service.matchPassword(password);
} catch (LoginException e1) {
warn("验证错误", e1.getMessage());
}
}
}
private void warn(String title, String msg) {
JOptionPane.showMessageDialog(null, msg, title, JOptionPane.INFORMATION_MESSAGE);
}
public static void main(String[] args) {
new LoinWindow().launch();
}
}
然后是模型层:LoginDao
public class LoginDao {
public boolean login(String username, String password) {
if(username.equals("admin")password.equals("12345")) {
return true;
}
return false;
}
}
LoginService
import java.util.regex.Pattern;
public class LoginService {
private static final Pattern LOGIN_PATTERN = Pattern.compile("[a-zA-Z] ");
private static final Pattern PASSWORD_PATTERN = Pattern.compile("[1-9] ");
private LoginDao dao = new LoginDao();
public boolean matchUsername(String username) throws LoginException {
if(null == username || username.isEmpty()) {
return false;
}
if(!LOGIN_PATTERN.matcher(username).matches()) {
throw new LoginException("您输入的用户名不合法,请输入英文!");
}
return true;
}
public boolean matchPassword(String password) throws LoginException {
if(null == password || password.isEmpty()) {
return false;
}
if(!PASSWORD_PATTERN.matcher(password).matches()) {
throw new LoginException("您输入的密码不合法 , 请输入数字!");
}
return true;
}
public boolean login(String username, String password) {
if(null == username || username.isEmpty()) {
return false;
}
if(null == password || password.isEmpty()) {
return false;
}
if(!dao.login(username, password)) {
return false;
}
return true;
}
}
LoginException
public class LoginException extends Exception {
public LoginException(String arg0) {
super(arg0);
}
}
不知道分层设计思想是不是我想的这样
java实现功能代码的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于java编写代码、java实现功能代码的信息别忘了在本站进行查找喔 。

    推荐阅读