很簡單的應用,為了節省字數,代碼注釋我就不加了
首先是顯示層,LoinWindow:
importjava.awt.FlowLayout;
importjava.awt.GridBagConstraints;
importjava.awt.GridBagLayout;
importjava.awt.GridLayout;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.FocusEvent;
importjava.awt.event.FocusListener;
importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;
importjavax.swing.JPanel;
importjavax.swing.JTextField;
importjavax.swing.border.EmptyBorder;
,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{
_PATTERN=Pattern.compile("[a-zA-Z]+");
_PATTERN=Pattern.compile("[1-9]+");
privateLoginDao=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(!.login(username,password)){
returnfalse;
}
returntrue;
}
}
LoginException
{
publicLoginException(Stringarg0){
super(arg0);
}
}
不知道分層設計思想是不是我想的這樣
B. java如何實現屏幕錄制功能
這種功能一本不用JAVA寫,因為他要和系統的本地資源打交道。
你可以使用VC、VB、delphi這類原生開發工具做。
也可以使用C#來寫。
C. 用java編寫一個控制台應用程序,實現如下功能:
importjava.util.Scanner;
publicclassAA{
publicstaticvoidmain(String[]args){
=newScanner(System.in);
System.out.println("請輸入:");
Stringstr=sc.nextLine();
System.out.println(str);
Strings1=str.substring(0,str.indexOf(""));
Strings2=str.substring(str.indexOf("")+1,str.length());
intc=Integer.parseInt(s2);
if(c<60){
if("-a".equals(s1)){
System.out.println("E");
}else{
System.out.println("不及格");
}
}elseif(c<70){
if("-a".equals(s1)){
System.out.println("D");
}else{
System.out.println("及格");
}
}elseif(c<80){
if("-a".equals(s1)){
System.out.println("C");
}else{
System.out.println("中等");
}
}elseif(c<90){
if("-a".equals(s1)){
System.out.println("B");
}else{
System.out.println("良好");
}
}else{
if("-a".equals(s1)){
System.out.println("A");
}else{
System.out.println("優秀");
}
}
}
}
D. 用java web實現 『視頻錄制 ,播放 ,保存『功能
java web實現視頻的基本很少,能完整運行的基本沒有.視頻錄制只能使用flash,所以你搜一搜java falsh還是能搜到一些的