這個(gè)圖形對(duì)吧?
創(chuàng)新互聯(lián)專注于企業(yè)全網(wǎng)整合營(yíng)銷推廣、網(wǎng)站重做改版、西秀網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、HTML5、商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為西秀等各大城市提供網(wǎng)站開(kāi)發(fā)制作服務(wù)。
*
***
*****
*******
*****
***
*
你確定不是 for/while/do-while loop?if 不是循環(huán)語(yǔ)句吧
用for loop做的:
public class NestedLoop{
public static void main (String[] args){
for (int i=0; i7; i++){
if (i %2 == 0){
for (int s=0; s(7-i-1)/2; s++){
System.out.print(" ");
}
for (int d=0; di +1; d++){
System.out.print("*");
}
System.out.println();
}
}
for (int i=5; i-1; i--){
if (i %2 == 0){
for (int s=0; s(7-i-1)/2; s++){
System.out.print(" ");
}
for (int d=0; di+1; d++){
System.out.print("*");
}
System.out.println();
}
}
}
}
給點(diǎn)分唄?我時(shí)差黨,大半夜12點(diǎn)多跟這給你做題~ ^ ^
這種功能一本不用JAVA寫(xiě),因?yàn)樗拖到y(tǒng)的本地資源打交道。
你可以使用VC、VB、delphi這類原生開(kāi)發(fā)工具做。
也可以使用C#來(lái)寫(xiě)。
可以,java功能可是相當(dāng)強(qiáng)大的。
這個(gè)是調(diào)用應(yīng)用程序的代碼:
Runtime ec;
ec=Runtime.getRuntime();
ec.exec("這里是應(yīng)用程序的路徑或者命令");
比如:ec.exec("c:\\123.exe");
很簡(jiǎn)單的應(yīng)用,為了節(jié)省字?jǐn)?shù),代碼注釋我就不加了
首先是顯示層,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("失敗",?"您輸入的用戶名或密碼錯(cuò)誤?!");
}
}
}
@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("驗(yàn)證錯(cuò)誤",?e1.getMessage());
}
}?else?if(source?==?tfPsd)?{
String?password?=?tfPsd.getText();
try?{
service.matchPassword(password);
}?catch?(LoginException?e1)?{
warn("驗(yàn)證錯(cuò)誤",?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("您輸入的用戶名不合法,請(qǐng)輸入英文!");
}
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("您輸入的密碼不合法,請(qǐng)輸入數(shù)字!");
}
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);
}
}
不知道分層設(shè)計(jì)思想是不是我想的這樣
底層的我不會(huì),不知調(diào)用那個(gè)工具包,看樓下的啦. 樓下的,好象可以通過(guò)虛擬機(jī)調(diào)用win32 API的啦,樓下去翻翻資料.