package image;
在滴道等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站建设、网站制作 网站设计制作按需规划网站,公司网站建设,企业网站建设,成都品牌网站建设,全网营销推广,外贸网站制作,滴道网站建设费用合理。
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class PanelRunner extends JFrame
{
private static final long serialVersionUID = 1L;
private static void initPanels ( JFrame pr )
{
for ( int i = 0; i 5; i++ )
{
JPanel panel = new JPanel ();
switch (i)
{
case 0:
panel.setBackground (Color.RED);
panel.setPreferredSize (new Dimension (200, 100));
pr.add (panel, BorderLayout.NORTH);
break;
case 1:
panel.setBackground (Color.YELLOW);
panel.setPreferredSize (new Dimension (200, 300));
pr.add (panel, BorderLayout.EAST);
break;
case 2:
panel.setBackground (Color.ORANGE);
panel.setPreferredSize (new Dimension (200, 100));
pr.add (panel, BorderLayout.SOUTH);
break;
case 3:
panel.setBackground (Color.WHITE);
panel.setPreferredSize (new Dimension (200, 300));
pr.add (panel, BorderLayout.WEST);
break;
case 4:
pr.add (panel, BorderLayout.CENTER);
panel.setPreferredSize (new Dimension (200, 100));
panel.setLayout (new GridLayout (1, 2));
for ( int j = 0; j 2; j++ )
{
JPanel subPanel = new JPanel ();
subPanel.setPreferredSize (new Dimension (200, 100));
Color color = j == 0 ? Color.BLUE : Color.GREEN;
subPanel.setBackground (color);
panel.add (subPanel);
}
break;
default:
break;
}
}
}
private static void initFrame ( JFrame pr )
{
pr.setLayout (new BorderLayout ());
pr.setSize (600, 300);
pr.setLocationRelativeTo (null);
pr.setResizable (false);
pr.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}
public static void main ( String[] args )
{
SwingUtilities.invokeLater (new Runnable ()
{
@Override
public void run ()
{
PanelRunner pr = new PanelRunner ();
initFrame (pr);
initPanels (pr);
pr.setVisible (true);
}
});
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java点虐 .*;
import java.io.*;
public class ClientDemo01 {
public static void main(String[] args){
JFrame f=new JFrame("AA");
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JTextArea ta=new JTextArea(15,30);
ta.setEditable(false); //文本域只读
JScrollPane sp=new JScrollPane(ta); //滚动窗格
JTextField tf=new JTextField(20);
JButton b=new JButton("发送");
p1.add(sp);
p2.add(tf);
p2.add(b);
f.add(p1,"Center");
f.add(p2,"South");
f.setBounds(300,300,360,300);
f.setVisible(true);
f.setResizable(false);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Socket socket=null;
BufferedInputStream bis=null;
BufferedOutputStream bos=null;
try{
socket=new Socket("192.168.0.4",5000);
bis=new BufferedInputStream(socket.getInputStream());
bos=new BufferedOutputStream(socket.getOutputStream());
MyThread01 mt=new MyThread01(bis,ta);
mt.start();
}catch(Exception e){
e.printStackTrace();
}
b.addActionListener(new ButtonActionListener01(tf,ta,bos));
}
}
class ButtonActionListener01 implements ActionListener{
JTextField tf;
JTextArea ta;
BufferedOutputStream bos;
public ButtonActionListener01(JTextField tf,JTextArea ta,BufferedOutputStream bos){
this.tf=tf;
this.ta=ta;
this.bos=bos;
}
public void actionPerformed(ActionEvent e){
String message=tf.getText();
if(!message.equals("")){
tf.setText(""); //清空文本框
ta.append("AA:"+message+"\n"); //添加到文本域并换行
try{
bos.write(message.getBytes());
bos.flush();
}catch(Exception ex){
System.out.println("发送失败");
}
}
}
}
class MyThread01 extends Thread{
BufferedInputStream bis;
JTextArea ta;
public MyThread01(BufferedInputStream bis,JTextArea ta){
this.bis=bis;
this.ta=ta;
}
public void run(){
try{
while(true){
byte[] b=new byte[100];
int length=bis.read(b);
String message=new String(b,0,length);
ta.append("BB:"+message+"\n");
}
}catch(Exception e){
e.printStackTrace();
}
}
} import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java点虐 .*;
import java.io.*;
public class ServerDemo01{
public static void main(String[] args){
JFrame f=new JFrame("BB");
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JTextArea ta=new JTextArea(12,30); //文本域,第一个参数为行数,第二个参数为列数
ta.setEditable(false); //文本域只读
JScrollPane sp=new JScrollPane(ta); //滚动窗格
JTextField tf=new JTextField(20);
JButton b=new JButton("发送");
p1.add(sp);
p2.add(tf);
p2.add(b);
f.add(p1,"Center");
f.add(p2,"South");
f.setBounds(300,300,360,300);
f.setVisible(true);
f.setResizable(false);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ServerSocket server=null;
Socket socket=null;
BufferedInputStream bis=null;
BufferedOutputStream bos=null;
try{
server=new ServerSocket(5000);
//ta.append("等待AA连接...\n");
socket=server.accept();
//ta.append("AA已连接\n");
bis=new BufferedInputStream(socket.getInputStream());
bos=new BufferedOutputStream(socket.getOutputStream());
MyThread1 mt=new MyThread1(bis,ta);
mt.start();
}catch(Exception e){
e.printStackTrace();
}
b.addActionListener(new ButtonActionListener1(tf,ta,bos));
}
}
class ButtonActionListener1 implements ActionListener{
JTextField tf;
JTextArea ta;
BufferedOutputStream bos;
public ButtonActionListener1(JTextField tf,JTextArea ta,BufferedOutputStream bos){
this.tf=tf;
this.ta=ta;
this.bos=bos;
}
public void actionPerformed(ActionEvent e){
String message=tf.getText(); //获取文本框中的内容
if(!message.equals("")){
tf.setText(""); //清空文本框
ta.append("BB:"+message+"\n"); //添加到文本域并换行
try{
bos.write(message.getBytes());
bos.flush();
}catch(Exception ex){
System.out.println("发送失败!");
}
}
}
}
class MyThread1 extends Thread{
BufferedInputStream bis;
JTextArea ta;
public MyThread1(BufferedInputStream bis,JTextArea ta){
this.bis=bis;
this.ta=ta;
}
public void run(){
try{
while(true){
byte[] b=new byte[100];
int length=bis.read(b);
String message=new String(b,0,length);
ta.append("AA:"+message+"\n");
}
}catch(Exception e){
e.printStackTrace();
}
}
}
怎么用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++等来实现图形化介面设计呢。
import java.applet.*;
import java.awt.Color;
import java.awt.Frame;
import javax.swing.JFrame;
import java.awt.event.*;
public class FirstFrame extends Frame {
public static void main(String args[]) {
FirstFrame fr = new FirstFrame("First contianer!");
fr.setSize(240, 240);
//继承JFrame的关闭窗口代码
//fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//继承Frame的
fr.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);//退出系统
}
});
fr.setVisible(true);
}
public FirstFrame(String str) {
super(str);
}
}
名称栏目:java窗口类代码 java 窗口
标题来源:https://www.cdcxhl.com/article28/ddgdcjp.html
成都网站建设公司_创新互联,为您提供外贸建站、企业建站、App开发、网站内链、、服务器托管
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联