怎么用java寫一個(gè)窗體程式?
成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供紅安網(wǎng)站建設(shè)、紅安做網(wǎng)站、紅安網(wǎng)站設(shè)計(jì)、紅安網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、紅安企業(yè)網(wǎng)站模板建站服務(wù),十多年紅安做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
下面介紹如何用簡(jiǎn)單的幾句話在eclipse環(huán)境下出現(xiàn)一個(gè)視窗。
首先寫一個(gè)frame類,繼承Frame,是繼承widows 然后把,出現(xiàn)視窗的語(yǔ)句封裝成一個(gè)函式
public void lunchFrame(){
this.setLocation(0,0);
this.setSize(20,20);
setVisible(True); ?一定要寫這句話
}
最后只需要在主函式里面呼叫就可以
Java是一門面向物件程式語(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可以編寫桌面應(yīng)用程式、Web應(yīng)用程式、分散式系統(tǒng)和嵌入式系統(tǒng)應(yīng)用程式等。
怎么用c#寫一個(gè)程式讓一個(gè)標(biāo)簽繞窗體走一圈
這個(gè)功能很奇葩,樓主說(shuō)的是窗體應(yīng)用程式么?如果是的話,這是原始碼。
怎么用JAVA寫一個(gè)使用者登入程式
同意樓上的說(shuō)法,具體點(diǎn)可以這樣:建立一個(gè)使用者表,里邊包括LoginName(登入名),UserName(使用者名稱),Password(密碼),Age(年齡),Address(地址)。然后編寫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ù)查詢操作的類: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í)體使用者類: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;
}
}
然后編寫控制層(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)寫的使用者登入程式。
用java編寫一個(gè)窗體資料輸入比較程式
使用畫圖功能,關(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寫一個(gè)tomcat的啟動(dòng),停止程式
可以利用Runtime類,Runtime用于別是虛擬機(jī)器執(zhí)行時(shí)的狀態(tài),它用于封裝JVM虛擬機(jī)器程序。
看看,我給你寫個(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();
}
}
如題,寫一個(gè)小程式,用swing介面的桌面應(yīng)用程式就行,用來(lái)啟動(dòng)、停止tomcat伺服器,啟動(dòng)后不顯示那個(gè)cmd視窗
怎么用vc++寫一個(gè)登陸的視窗程式
哥連資料庫(kù)不?ado還是odbc?什么資料庫(kù)?
怎么用JAVA來(lái)寫一個(gè)小游戲程式
首先你應(yīng)該要具備程式設(shè)計(jì)的基礎(chǔ)知識(shí)水平,利用Elicpse等軟體來(lái)寫程式碼,既而來(lái)實(shí)現(xiàn)相應(yīng)的功能,也可以用VC++等來(lái)實(shí)現(xiàn)圖形化介面設(shè)計(jì)呢。
mypl8110627 的方法當(dāng)然是可以的,但是如果要考慮任務(wù)欄高度之類的還要調(diào)用 getScreenInsets() 方法。
其實(shí)有一個(gè)更簡(jiǎn)單的方法,只要一句話:你在 f.setSize(500, 600); 下面再加上:f.setLocationRelativeTo(null); 就OK了。
setLocationRelativeTo(null);這個(gè)方法是使用了絕對(duì)布局···在窗口的放大縮小時(shí)不會(huì)改變?cè)榷x號(hào)的位置···!
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);
}
}
窗體寫好了,運(yùn)算你自己寫
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();
}
}