大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
窗体写好了,运算你自己写
江南ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!
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("第一个数字");
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("结果为");
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("简易计算器"));
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.*;/***多线程,小球演示.打开Windows任务管理器,可看到线程变化。可搜索到,run()方法/.start()**du:程序技巧体会:所谓产生一个小球,即是new其类对象,其属性携带画小球的坐标、颜色、所在容器等参数。**一个类,属性用来作为参数容器用,方法.完成功能。**///运行类publicclassBouncePress{//publicstaticvoidmain(String[]args){JFrameframe=newBouncePressFrame();//生成窗口。执行构造。-----业务逻辑。frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//similarto//window//listenerframe.show();}}classBouncePressFrameextendsJFrame{privateBallPressCanvascanvas;publicBouncePressFrame(){setSize(600,500);//窗口大小setTitle("BounceBall");ContainercontentPane=getContentPane();//Swing的窗口不能直接放入东西,只能在其上的ContentPane上放。canvas=newBallPressCanvas();//生成一个新面板。-----canvascontentPane.add(canvas,BorderLayout.CENTER);//窗口中心加入该面板。JPanelbuttonPanel=newJPanel();//再生成一个新面板。----buttonPanel//调用本类方法addButton。addButton(buttonPanel,"Start",//生成一个按钮"Start"---加入面板buttonPanelnewActionListener(){//|------按钮绑上action监听器。publicvoidactionPerformed(ActionEventevt){//|小球容器对象的addBall(Thread.NORM_PRIORITY-4,Color.black);//事件处理时,执行---addBall()方法。---产生小球(参数对象)---加入List中---开始画球。}});//按一次,addBall()一次---产生一个新小球---加入List中---开始画此新小球。//---画球线程BallPressThread的run()---小球(参数对象).move()---每次画时,先移动,再判断,再画。//---BallPressCanvas类的canvas对象.paint()---自动调BallPressCanvas类的paintComponent(Graphics//g)方法。//---该方法,从List中循环取出所有小球,第i个球,---调该小球BallPress类//.draw()方法---调Graphics2D方法画出小球。--使用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);//生成一个按钮。c.add(button);//加入容器中。button.addActionListener(listener);//按钮绑上action监听器。}/**主要业务方法。*/publicvoidaddBall(intpriority,Colorcolor){//生成小球(参数对象)BallPressb=newBallPress(canvas,color);//生成BallPress对象,携带、初始化//画Ball形小球,所需参数:所在容器组件,所需color--black/red.//小球加入List中。canvas.add(b);//面板canvas的ArrayList中加入BallPress对象。BallPressThreadthread=newBallPressThread(b);//生成画小球的线程类BallPressThread对象。传入BallPress对象(携带了画球所需//容器、color参数)。thread.setPriority(priority);thread.start();//callrun(),ballstarttomove//画球线程开始。---BallPressThread的run()---小球(参数对象).move()---先移动,再画。canvas.paint---BallPressCanvas类的}}//画球的线程类。classBallPressThreadextendsThread{privateBallPressb;publicBallPressThread(BallPressaBall){b=aBall;}//画球开始。publicvoidrun(){try{for(inti=1;i自动绘制面板,且自动调paintComponent(Graphics//g)方法,---重写该方法,绘制面板(及其上组件)。//作用2)该类对象属性ArrayListballs---兼作小球(参数对象)的容器。classBallPressCanvasextendsJPanel{privateArrayListballs=newArrayList();publicvoidadd(BallPressb){balls.add(b);//向ArrayList中添加球。当按下按钮,添加多个球时,都保存在这个List中。}//重写了javax.swing.JComponent的paintComponent()方法。//paint()方法自动调用该方法。publicvoidpaintComponent(Graphicsg){super.paintComponent(g);Graphics2Dg2=(Graphics2D)g;for(inti=0;i=canvas.getWidth()){//小球右边已经到画板右边。x=canvas.getWidth()-15;dx=-dx;//开始反向运动。}if(y=canvas.getHeight()){//小球已到画板顶。y=canvas.getHeight()-15;dy=-dy;}canvas.paint(canvas.getGraphics());//画出面板对象canvas----(及其上所有组件)////.paint()方法,自动调用}}/*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();}}不懂的再问啊。。。
怎么用java写一个窗体程式?
下面介绍如何用简单的几句话在eclipse环境下出现一个视窗。
首先写一个frame类,继承Frame,是继承widows 然后把,出现视窗的语句封装成一个函式
public void lunchFrame(){
this.setLocation(0,0);
this.setSize(20,20);
setVisible(True); 一定要写这句话
}
最后只需要在主函式里面呼叫就可以
Java是一门面向物件程式语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指标等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向物件程式语言的代表,极好地实现了面向物件理论,允许程式设计师以优雅的思维方式进行复杂的程式设计 。
Java具有简单性、面向物件、分散式、健壮性、安全性、平台独立与可移植性、多执行绪、动态性等特点 。Java可以编写桌面应用程式、Web应用程式、分散式系统和嵌入式系统应用程式等。
怎么用c#写一个程式让一个标签绕窗体走一圈
这个功能很奇葩,楼主说的是窗体应用程式么?如果是的话,这是原始码。
怎么用JAVA写一个使用者登入程式
同意楼上的说法,具体点可以这样:建立一个使用者表,里边包括LoginName(登入名),UserName(使用者名称),Password(密码),Age(年龄),Address(地址)。然后编写Java程式(用MVC架构)模型层(M):DBConnection.java(负责连线资料库)
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个负责资料库查询操作的类: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个实体使用者类: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个Jsp(登入页面GetInfo.jsp、登入成功页面GetInfoUser.jsp、登入失败页面GetInfoFinale.jsp)
上面的就是Jsp结合Servlet用MVC架构写的使用者登入程式。
用java编写一个窗体资料输入比较程式
使用画图功能,关于比较那是很简单的逻辑
JFrame frame = new JFrame("XXX");
ShootGame game = new ShootGame(); 面板物件
frame.add(game); 将面板新增到JFrame中
frame.setSize(WIDTH, HEIGHT); 设定大小
frame.setAlwaysOnTop(true); 设定其总在最上
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 预设关闭操作
frame.setIconImage(new ImageIcon("images/icon.jpg").getImage()); 设定窗体的图示
frame.setLocationRelativeTo(null); 设定窗体初始位置
frame.setVisible(true); 尽快呼叫paint
game.action(); 启动执行
怎么用java写一个tomcat的启动,停止程式
可以利用Runtime类,Runtime用于别是虚拟机器执行时的状态,它用于封装JVM虚拟机器程序。
看看,我给你写个程式码:
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();
}
}
如题,写一个小程式,用swing介面的桌面应用程式就行,用来启动、停止tomcat伺服器,启动后不显示那个cmd视窗
怎么用vc++写一个登陆的视窗程式
哥连资料库不?ado还是odbc?什么资料库?
怎么用JAVA来写一个小游戏程式
首先你应该要具备程式设计的基础知识水平,利用Elicpse等软体来写程式码,既而来实现相应的功能,也可以用VC++等来实现图形化介面设计呢。
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();}/***下面是具体实现*/JTextFieldtext;JButtonbutton;JEditorPanetextArea;publicWindowTest(){super("测试窗体");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; //一个按钮
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);
}
}