窗體寫(xiě)好了,運(yùn)算你自己寫(xiě)
江南ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書(shū)銷(xiāo)售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書(shū)合作)期待與您的合作!
import java.awt.Button;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class SimpleCalculator {
private JFrame f = new JFrame();
private JPanel firstPanel = new JPanel();
private JLabel firstNumLabel = new JLabel("第一個(gè)數(shù)字");
private JTextField number1 = new JTextField();
private JPanel secondPanel = new JPanel();
private Button add = new Button("+");
private Button mul = new Button("*");
private Button clear = new Button("清除");
private JPanel thirdPanel = new JPanel();
private JLabel resultLabel = new JLabel("結(jié)果為");
private JTextField result = new JTextField();
public SimpleCalculator(){
firstPanel.setLayout(new GridLayout(1, 2));
firstPanel.add(firstNumLabel);
firstPanel.add(number1);
secondPanel.setLayout(new GridLayout(1, 3));
secondPanel.add(add);
secondPanel.add(mul);
secondPanel.add(clear);
thirdPanel.setLayout(new GridLayout(1, 2));
thirdPanel.add(resultLabel);
thirdPanel.add(result);
f.add(new JLabel("簡(jiǎn)易計(jì)算器"));
f.add(firstPanel);
f.add(secondPanel);
f.add(thirdPanel);
f.setLayout(new GridLayout(4, 1));
f.setVisible(true);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new SimpleCalculator();
}
}
importjava.awt.*;importjava.awt.event.*;importjava.awt.geom.*;importjava.util.*;importjavax.swing.*;/***多線程,小球演示.打開(kāi)Windows任務(wù)管理器,可看到線程變化??伤阉鞯剑瑀un()方法/.start()**du:程序技巧體會(huì):所謂產(chǎn)生一個(gè)小球,即是new其類(lèi)對(duì)象,其屬性攜帶畫(huà)小球的坐標(biāo)、顏色、所在容器等參數(shù)。**一個(gè)類(lèi),屬性用來(lái)作為參數(shù)容器用,方法.完成功能。**///運(yùn)行類(lèi)publicclassBouncePress{//publicstaticvoidmain(String[]args){JFrameframe=newBouncePressFrame();//生成窗口。執(zhí)行構(gòu)造。-----業(yè)務(wù)邏輯。frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//similarto//window//listenerframe.show();}}classBouncePressFrameextendsJFrame{privateBallPressCanvascanvas;publicBouncePressFrame(){setSize(600,500);//窗口大小setTitle("BounceBall");ContainercontentPane=getContentPane();//Swing的窗口不能直接放入東西,只能在其上的ContentPane上放。canvas=newBallPressCanvas();//生成一個(gè)新面板。-----canvascontentPane.add(canvas,BorderLayout.CENTER);//窗口中心加入該面板。JPanelbuttonPanel=newJPanel();//再生成一個(gè)新面板。----buttonPanel//調(diào)用本類(lèi)方法addButton。addButton(buttonPanel,"Start",//生成一個(gè)按鈕"Start"---加入面板buttonPanelnewActionListener(){//|------按鈕綁上action監(jiān)聽(tīng)器。publicvoidactionPerformed(ActionEventevt){//|小球容器對(duì)象的addBall(Thread.NORM_PRIORITY-4,Color.black);//事件處理時(shí),執(zhí)行---addBall()方法。---產(chǎn)生小球(參數(shù)對(duì)象)---加入List中---開(kāi)始畫(huà)球。}});//按一次,addBall()一次---產(chǎn)生一個(gè)新小球---加入List中---開(kāi)始畫(huà)此新小球。//---畫(huà)球線程BallPressThread的run()---小球(參數(shù)對(duì)象).move()---每次畫(huà)時(shí),先移動(dòng),再判斷,再畫(huà)。//---BallPressCanvas類(lèi)的canvas對(duì)象.paint()---自動(dòng)調(diào)BallPressCanvas類(lèi)的paintComponent(Graphics//g)方法。//---該方法,從List中循環(huán)取出所有小球,第i個(gè)球,---調(diào)該小球BallPress類(lèi)//.draw()方法---調(diào)Graphics2D方法畫(huà)出小球。--使用color/addButton(buttonPanel,"Express",newActionListener(){publicvoidactionPerformed(ActionEventevt){addBall(Thread.NORM_PRIORITY+2,Color.red);}});addButton(buttonPanel,"Close",newActionListener(){publicvoidactionPerformed(ActionEventevt){System.exit(0);}});contentPane.add(buttonPanel,BorderLayout.SOUTH);}publicvoidaddButton(Containerc,Stringtitle,ActionListenerlistener){JButtonbutton=newJButton(title);//生成一個(gè)按鈕。c.add(button);//加入容器中。button.addActionListener(listener);//按鈕綁上action監(jiān)聽(tīng)器。}/**主要業(yè)務(wù)方法。*/publicvoidaddBall(intpriority,Colorcolor){//生成小球(參數(shù)對(duì)象)BallPressb=newBallPress(canvas,color);//生成BallPress對(duì)象,攜帶、初始化//畫(huà)Ball形小球,所需參數(shù):所在容器組件,所需color--black/red.//小球加入List中。canvas.add(b);//面板canvas的ArrayList中加入BallPress對(duì)象。BallPressThreadthread=newBallPressThread(b);//生成畫(huà)小球的線程類(lèi)BallPressThread對(duì)象。傳入BallPress對(duì)象(攜帶了畫(huà)球所需//容器、color參數(shù))。thread.setPriority(priority);thread.start();//callrun(),ballstarttomove//畫(huà)球線程開(kāi)始。---BallPressThread的run()---小球(參數(shù)對(duì)象).move()---先移動(dòng),再畫(huà)。canvas.paint---BallPressCanvas類(lèi)的}}//畫(huà)球的線程類(lèi)。classBallPressThreadextendsThread{privateBallPressb;publicBallPressThread(BallPressaBall){b=aBall;}//畫(huà)球開(kāi)始。publicvoidrun(){try{for(inti=1;i自動(dòng)繪制面板,且自動(dòng)調(diào)paintComponent(Graphics//g)方法,---重寫(xiě)該方法,繪制面板(及其上組件)。//作用2)該類(lèi)對(duì)象屬性ArrayListballs---兼作小球(參數(shù)對(duì)象)的容器。classBallPressCanvasextendsJPanel{privateArrayListballs=newArrayList();publicvoidadd(BallPressb){balls.add(b);//向ArrayList中添加球。當(dāng)按下按鈕,添加多個(gè)球時(shí),都保存在這個(gè)List中。}//重寫(xiě)了javax.swing.JComponent的paintComponent()方法。//paint()方法自動(dòng)調(diào)用該方法。publicvoidpaintComponent(Graphicsg){super.paintComponent(g);Graphics2Dg2=(Graphics2D)g;for(inti=0;i=canvas.getWidth()){//小球右邊已經(jīng)到畫(huà)板右邊。x=canvas.getWidth()-15;dx=-dx;//開(kāi)始反向運(yùn)動(dòng)。}if(y=canvas.getHeight()){//小球已到畫(huà)板頂。y=canvas.getHeight()-15;dy=-dy;}canvas.paint(canvas.getGraphics());//畫(huà)出面板對(duì)象canvas----(及其上所有組件)////.paint()方法,自動(dòng)調(diào)用}}/*importjava.awt.*;importjava.awt.event.*;importjava.awt.geom.*;importjava.util.*;importjavax.swing.*;*//***單線程,小球演示搜索不到,run()方法/.start()*//*publicclassBounce{publicstaticvoidmain(String[]args){JFrameframe=newBounceFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//similarto//window//listenerframe.show();}}不懂的再問(wèn)啊。。。
怎么用java寫(xiě)一個(gè)窗體程式?
下面介紹如何用簡(jiǎn)單的幾句話在eclipse環(huán)境下出現(xiàn)一個(gè)視窗。
首先寫(xiě)一個(gè)frame類(lèi),繼承Frame,是繼承widows 然后把,出現(xiàn)視窗的語(yǔ)句封裝成一個(gè)函式
public void lunchFrame(){
this.setLocation(0,0);
this.setSize(20,20);
setVisible(True); ?一定要寫(xiě)這句話
}
最后只需要在主函式里面呼叫就可以
Java是一門(mén)面向物件程式語(yǔ)言,不僅吸收了C++語(yǔ)言的各種優(yōu)點(diǎn),還摒棄了C++里難以理解的多繼承、指標(biāo)等概念,因此Java語(yǔ)言具有功能強(qiáng)大和簡(jiǎn)單易用兩個(gè)特征。Java語(yǔ)言作為靜態(tài)面向物件程式語(yǔ)言的代表,極好地實(shí)現(xiàn)了面向物件理論,允許程式設(shè)計(jì)師以優(yōu)雅的思維方式進(jìn)行復(fù)雜的程式設(shè)計(jì) 。
Java具有簡(jiǎn)單性、面向物件、分散式、健壯性、安全性、平臺(tái)獨(dú)立與可移植性、多執(zhí)行緒、動(dòng)態(tài)性等特點(diǎn) 。Java可以編寫(xiě)桌面應(yīng)用程式、Web應(yīng)用程式、分散式系統(tǒng)和嵌入式系統(tǒng)應(yīng)用程式等。
怎么用c#寫(xiě)一個(gè)程式讓一個(gè)標(biāo)簽繞窗體走一圈
這個(gè)功能很奇葩,樓主說(shuō)的是窗體應(yīng)用程式么?如果是的話,這是原始碼。
怎么用JAVA寫(xiě)一個(gè)使用者登入程式
同意樓上的說(shuō)法,具體點(diǎn)可以這樣:建立一個(gè)使用者表,里邊包括LoginName(登入名),UserName(使用者名稱(chēng)),Password(密碼),Age(年齡),Address(地址)。然后編寫(xiě)Java程式(用MVC架構(gòu))模型層(M):DBConnection.java(負(fù)責(zé)連線資料庫(kù))
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
public class DBConnection {
private static final String DRIVER_CLASS = "sun.jdbc.odbc.JdbcOdbcDriver";
private static final String DB_URL = "jdbc:odbc:text";
public DBConnection() {
}
public static Connection getConnection() {
Connection conn = null;
try {
Class.forName(DRIVER_CLASS);
conn = DriverManager.getConnection(DB_URL);
} catch (SQLException ex) {
System.out.println(ex.getMessage());
} catch (ClassNotFoundException ex) {
System.out.println(ex.getMessage());
}
return conn;
}
}
第2個(gè)負(fù)責(zé)資料庫(kù)查詢操作的類(lèi):DBUserManager.java
import edu.sys.text.model.entity.User;
import edu.sys.text.model.dao.DBConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.*;
public class DBUserManager {
private static final String SQL_SELECT =
"SELECT LoginName,UserName,PassWord,Age,Address FROM UserInfo WHERE LoginName = ? AND PassWord = ?";
public DBUserManager() {
}
public boolean checkDB(User u) {
boolean b = false;
Connection conn = null;
PreparedStatement p *** t = null;
ResultSet rs = null;
conn = DBConnection.getConnection();
try {
p *** t = conn.prepareStatement(SQL_SELECT);
p *** t.setString(1, u.getLoginName());
p *** t.setString(2, u.getPassWord());
rs = p *** t.executeQuery();
b = rs.next();
if (rs.next()) {
b = true;
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
} finally {
cleanDB(rs, p *** t, conn);
}
return b;
}
public User checkBC(User u) {
Connection conn = null;
PreparedStatement p *** t = null;
ResultSet rs = null;
User tmp = new User();
conn = DBConnection.getConnection();
try {
p *** t = conn.prepareStatement(SQL_SELECT);
p *** t.setString(1, u.getLoginName());
p *** t.setString(2, u.getPassWord());
rs = p *** t.executeQuery();
if (rs.next()) {
tmp.setLoginName(rs.getString(1));
tmp.setUserName(rs.getString(2));
tmp.setAge(rs.getInt(4));
tmp.setAddress(rs.getString(5));
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
} finally {
cleanDB(rs, p *** t, conn);
}
return tmp;
}
public void cleanDB(ResultSet rs, PreparedStatement p *** t, Connection conn) {
try {
if (rs != null) {
rs.close();
}
if (p *** t != null) {
p *** t.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
第3個(gè)實(shí)體使用者類(lèi):User.java
package edu.sys.text.model.entity;
public class User {
private String loginName;
private String userName;
private String passWord;
private int age;
private String address;
public User() {
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public void setAge(int age) {
this.age = age;
}
public void setAddress(String address) {
this.address = address;
}
public String getLoginName() {
return loginName;
}
public String getUserName() {
return userName;
}
public String getPassWord() {
return passWord;
}
public int getAge() {
return age;
}
public String getAddress() {
return address;
}
}
然后編寫(xiě)控制層(C):GetInfoServlet.java
package edu.sys.text.control;
import javax.servlet.*;
import javax.servlet..*;
import java.io.*;
import java.util.*;
import edu.sys.text.model.entity.User;
import edu.sys.text.model.service.UserManager;
public class GetInfoServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/; charset=GBK";
Initialize global variables
public void init() throws ServletException {
}
Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
}
Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String loginName = request.getParameter("loginName");
String passWord = request.getParameter("passWord");
User u = new User();
u.setLoginName(loginName);
u.setPassWord(passWord);
UserManager m = new UserManager();
RequestDispatcher d;
if (m.checkUser(u)) {
User o = m.checkBC(u);
request.setAttribute("JavaBEAN",o);
d = request.getRequestDispatcher("GetInfoUser.jsp");
} else {
d = request.getRequestDispatcher("GetInfoFinale.jsp");
}
d.forward(request, response);
}
Clean up resources
public void destroy() {
}
}
最后,建立表示層(V):包括3個(gè)Jsp(登入頁(yè)面GetInfo.jsp、登入成功頁(yè)面GetInfoUser.jsp、登入失敗頁(yè)面GetInfoFinale.jsp)
上面的就是Jsp結(jié)合Servlet用MVC架構(gòu)寫(xiě)的使用者登入程式。
用java編寫(xiě)一個(gè)窗體資料輸入比較程式
使用畫(huà)圖功能,關(guān)于比較那是很簡(jiǎn)單的邏輯
JFrame frame = new JFrame("XXX");
ShootGame game = new ShootGame(); 面板物件
frame.add(game); 將面板新增到JFrame中
frame.setSize(WIDTH, HEIGHT); 設(shè)定大小
frame.setAlwaysOnTop(true); 設(shè)定其總在最上
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 預(yù)設(shè)關(guān)閉操作
frame.setIconImage(new ImageIcon("images/icon.jpg").getImage()); 設(shè)定窗體的圖示
frame.setLocationRelativeTo(null); 設(shè)定窗體初始位置
frame.setVisible(true); 盡快呼叫paint
game.action(); 啟動(dòng)執(zhí)行
怎么用java寫(xiě)一個(gè)tomcat的啟動(dòng),停止程式
可以利用Runtime類(lèi),Runtime用于別是虛擬機(jī)器執(zhí)行時(shí)的狀態(tài),它用于封裝JVM虛擬機(jī)器程序。
看看,我給你寫(xiě)個(gè)程式碼:
public class Run {
public static void main(String[] args) throws Exception {
Runtime run=Runtime.getRuntime();
Process process=run.exec("Tomcat.exe");
Thread.sleep(3000);
process.destroy();
}
}
如題,寫(xiě)一個(gè)小程式,用swing介面的桌面應(yīng)用程式就行,用來(lái)啟動(dòng)、停止tomcat伺服器,啟動(dòng)后不顯示那個(gè)cmd視窗
怎么用vc++寫(xiě)一個(gè)登陸的視窗程式
哥連資料庫(kù)不?ado還是odbc?什么資料庫(kù)?
怎么用JAVA來(lái)寫(xiě)一個(gè)小游戲程式
首先你應(yīng)該要具備程式設(shè)計(jì)的基礎(chǔ)知識(shí)水平,利用Elicpse等軟體來(lái)寫(xiě)程式碼,既而來(lái)實(shí)現(xiàn)相應(yīng)的功能,也可以用VC++等來(lái)實(shí)現(xiàn)圖形化介面設(shè)計(jì)呢。
importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.KeyEvent;importjava.awt.event.KeyListener;importjavax.swing.JButton;importjavax.swing.JEditorPane;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JTextField;publicclassWindowTestextendsJFrameimplementsActionListener,KeyListener{privatestaticfinallongserialVersionUID=1L;/***主方法*/publicstaticvoidmain(String[]args){WindowTestwin=newWindowTest();}/***下面是具體實(shí)現(xiàn)*/JTextFieldtext;JButtonbutton;JEditorPanetextArea;publicWindowTest(){super("測(cè)試窗體");text=newJTextField(15);text.addKeyListener(this);JPanelp1=newJPanel();p1.add(newJLabel("輸入字符:"));p1.add(text);button=newJButton("清除");button.addActionListener(this);p1.add(button);p1.setBounds(5,5,220,100);textArea=newJEditorPane();textArea.setBounds(1,1,216,200);JPanelp2=newJPanel();p2.add(newJLabel("顯示字符:"));p2.add(textArea);p2.setBounds(5,115,340,220);JPanelp3=newJPanel();p3.add(p1);p3.add(p2);add(p3);setBounds(160,60,400,300);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}@OverridepublicvoidkeyPressed(KeyEvente){}@OverridepublicvoidkeyReleased(KeyEvente){if(e.getKeyCode()==KeyEvent.VK_ENTER){textArea.setText("");}else{Stringstr=text.getText();textArea.setText(str);}}@OverridepublicvoidkeyTyped(KeyEvente){}@OverridepublicvoidactionPerformed(ActionEvente){text.setText("");textArea.setText("");}}
public?class?Demo?extends?JFrame
{
JButton?jb;?//一個(gè)按鈕
public?static?void?main(String?[]args){
new?Demo();
}
public?Demo()
{
this.setLayout(new?FlowLayout());
jb=new?JButton("按扭");
this.add(jb);
this.setSize(400,300);
this.setVisible(true);
this.setLocation(500,?200);
}
}
文章標(biāo)題:java中完整窗體代碼 java窗體程序
轉(zhuǎn)載源于:http://jinyejixie.com/article30/dochjso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、關(guān)鍵詞優(yōu)化、外貿(mào)建站、建站公司、網(wǎng)站設(shè)計(jì)公司、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)