java頁面
A. java界面設計
我覺得,頁面布局什麼的,這個不用說了吧。。就是邏輯而已,點擊「第一步」,判斷有沒有輸入,如果有輸入,判斷是不是正整數,如果條件符合,那麼第一格顯示輸入的值,然後第二格,處理下(其實就是for循環String,倒序)然後第三格=第一格+第二格的值;
第二步,同樣獲得第一步最後一個的和值,然後類似第一步。如下類似
B. Java 界面設計
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import java.awt.GridBagConstraints;
public class Test1 extends JPanel {
private static final long serialVersionUID = 1L;
private JSplitPane jSplitPane = null;
/**
* This is the default constructor
*/
public Test1() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.gridy = 0;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.gridx = 0;
this.setSize(300, 200);
this.setLayout(new GridBagLayout());
this.add(getJSplitPane(), gridBagConstraints);
}
/**
* This method initializes jSplitPane
*
* @return javax.swing.JSplitPane
*/
private JSplitPane getJSplitPane() {
if (jSplitPane == null) {
jSplitPane = new JSplitPane();
}
return jSplitPane;
}
}
樓主是不是要這種的效果???
C. java頁面怎麼取得jsp頁面的值
jsp在頁面上獲取java參數總共有以下方法:
(1)直接在URL請求後添加
如:<a href="thexuan.jsp?action=transparams&detail=directe")直接傳遞參數, 特別的在使用response.sendRedirect做頁面轉向的時候,也可以用如下代碼: response.sendRedirect("thexuan.jsp?action=transparams&detail=directe") ,可用request.getParameter(name)取得參數
(2)jsp:param
它可以實現主頁面向包含頁面傳遞參數,如下:
還可以實現在使用jsp:forward動作做頁面跳轉時傳遞參數,如下:
通過這種方式和一般的表單參數一樣的,也可以通過request.getParameter(name)取得參數
(3)設置session和request
通過顯示的把參數放置到session和request中,以達到傳遞參數的目的
session.setAttribute(name,value);
request.setAttribute(name,value)
取參數:value=(value className)session.getAttribute(name);
value=(value className)request.getAttribute(name);
D. 如何在HTML頁面中寫java代碼
Java要運行html代碼,需要運行在伺服器端,也就是servlet容器中,經過容器編譯解析,返回html靜態內容,示例如下:
在servlet裡面寫就可以了
引入一系列包
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
public class Servlet1 extends HttpServlet {
public void doGet(ServletRequest req,ServletResponse res)throws ServletException, IOException{try{PrintWriter pw=res.getWriter();//在瀏覽器輸出需要
pw.println("<script<script");}catch(exception e){="" e.printstacktrace();="" 為發現調試錯誤}}}=""
E. java實現簡單登錄界面
自己寫的比較規范的代碼,都有注釋:
import javax.swing.JFrame;//框架
import javax.swing.JPanel;//面板
import javax.swing.JButton;//按鈕
import javax.swing.JLabel;//標簽
import javax.swing.JTextField;//文本框
import java.awt.Font;//字體
import java.awt.Color;//顏色
import javax.swing.JPasswordField;//密碼框
import java.awt.event.ActionListener;//事件監聽
import java.awt.event.ActionEvent;//事件處理
import javax.swing.JOptionPane;//消息窗口
public class UserLogIn extends JFrame{
public JPanel pnluser;
public JLabel lbluserLogIn;
public JLabel lbluserName;
public JLabel lbluserPWD;
public JTextField txtName;
public JPasswordField pwdPwd;
public JButton btnSub;
public JButton btnReset;
public UserLogIn(){
pnluser = new JPanel();
lbluserLogIn = new JLabel();
lbluserName = new JLabel();
lbluserPWD = new JLabel();
txtName = new JTextField();
pwdPwd = new JPasswordField();
btnSub = new JButton();
btnReset = new JButton();
userInit();
}
public void userInit(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設置關閉框架的同時結束程序
this.setSize(300,200);//設置框架大小為長300,寬200
this.setResizable(false);//設置框架不可以改變大小
this.setTitle("用戶登錄");//設置框架標題
this.pnluser.setLayout(null);//設置面板布局管理
this.pnluser.setBackground(Color.cyan);//設置面板背景顏色
this.lbluserLogIn.setText("用戶登錄");//設置標簽標題
this.lbluserLogIn.setFont(new Font("宋體",Font.BOLD | Font.ITALIC,14));//設置標簽字體
this.lbluserLogIn.setForeground(Color.RED);//設置標簽字體顏色
this.lbluserName.setText("用戶名:");
this.lbluserPWD.setText("密 碼:");
this.btnSub.setText("登錄");
this.btnReset.setText("重置");
this.lbluserLogIn.setBounds(120,15,60,20);//設置標簽x坐標120,y坐標15,長60,寬20
this.lbluserName.setBounds(50,55,60,20);
this.lbluserPWD.setBounds(50,85,60,25);
this.txtName.setBounds(110,55,120,20);
this.pwdPwd.setBounds(110,85,120,20);
this.btnSub.setBounds(85,120,60,20);
this.btnSub.addActionListener(new ActionListener()//匿名類實現ActionListener介面
{
public void actionPerformed(ActionEvent e){
btnsub_ActionEvent(e);
}
}
);
this.btnReset.setBounds(155,120,60,20);
this.btnReset.addActionListener(new ActionListener()//匿名類實現ActionListener介面
{
public void actionPerformed(ActionEvent e){
btnreset_ActionEvent(e);
}
}
);
this.pnluser.add(lbluserLogIn);//載入標簽到面板
this.pnluser.add(lbluserName);
this.pnluser.add(lbluserPWD);
this.pnluser.add(txtName);
this.pnluser.add(pwdPwd);
this.pnluser.add(btnSub);
this.pnluser.add(btnReset);
this.add(pnluser);//載入面板到框架
this.setVisible(true);//設置框架可顯
}
public void btnsub_ActionEvent(ActionEvent e){
String name = txtName.getText();
String pwd = String.valueOf(pwdPwd.getPassword());
if(name.equals("")){
JOptionPane.showMessageDialog(null,"賬號不能為空","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}else if (pwd.equals("")){
JOptionPane.showMessageDialog(null,"密碼不能為空","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}else if(true){
this.dispose();
}else{
JOptionPane.showMessageDialog(null,"賬號或密碼錯誤","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}
}
public void btnreset_ActionEvent(ActionEvent e){
txtName.setText("");
pwdPwd.setText("");
}
public static void main(String[] args){
new UserLogIn();
}
}
F. java如何添加界面
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
public class app//類名最好大寫
{
static JFrame frm =new JFrame("清掃機器人模擬界面");
static ImageIcon bg = new ImageIcon("456.jpg");//背景圖片名稱,相對路徑
static JLabel lab=new JLabel(bg);//圖片放在標簽里
public static void main(String[] args) {
lab.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight());//設置圖片的大小
frm.getLayeredPane().add(lab,new Integer(Integer.MIN_VALUE));//把圖片設置在第二層
JPanel jp = (JPanel) frm.getContentPane();//獲取最上層JPanel
jp.setOpaque(false);//設置為透明
//JPanel jp2 = new JPanel();//如果要加按鈕什麼的就在這個jp2裡面加,不需要的話就用了
//jp2.setOpaque(false);
//frm.add(jp2);
frm.setLayout(null);
frm.setSize(1300,700);
//frm.setBackground(Color.blue);
frm.setVisible(true);
frm.addWindowListener(new WindowAdapter() {//關閉窗口的方法沒寫
@Override
public void windowClosing(WindowEvent e) {
frm.setVisible(false);
System.exit(0);
}
});
}
}
G. 用java做個如下界面
對於窗口的左側部分,存在幾種可能, 1: 可能是工具欄里的按鈕 2: 可能是選項卡 3: 一個按鈕
三種可能性我寫了三種參考代碼.(建議對問題的描述更加清晰,這樣可以得到更貼切的回答)
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
{
JPaneljp1;
publicSimpleDemo(){
initMenuBar();
JPaneljpWest=newJPanel();
JButtonjb=newJButton("拓撲");
jb.addActionListener(this);
jpWest.add(jb);
jp1=newJPanel();
jp1.setBackground(Color.RED);
jp1.setVisible(false);
add(jp1);
add(jpWest,BorderLayout.WEST);
setSize(300,200);//窗口大小
setLocationRelativeTo(null);//居中
setDefaultCloseOperation(EXIT_ON_CLOSE);//點擊關閉按鈕就退出
}
privatevoidinitMenuBar(){
JMenuBarjmb=newJMenuBar();
JMenujm1=newJMenu("系統");
JMenuItemitem1=newJMenuItem("退出");
item1.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
System.exit(0);//點擊退出菜單項時,結束程序
}
});
jm1.add(item1);
JMenujm2=newJMenu("幫助");
jmb.add(jm1);
jmb.add(jm2);
setJMenuBar(jmb);//設置本窗口的菜單欄
}
publicstaticvoidmain(String[]args){
SwingUtilities.invokeLater(newRunnable(){
publicvoidrun(){
newSimpleDemo().setVisible(true);//創建窗口並設置可見
}
});
}
@Override
publicvoidactionPerformed(ActionEvente){
jp1.setVisible(!jp1.isVisible());
}
}
H. JAVA頁面跳轉
a頁面代碼
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> page A </TITLE>
<script language="javascript">
function newWin(){
var str = window.showModalDialog("pageB.html",null,"dialogWidth=400px;dialogHeight=300px");
if (typeof(str) == "undefined") {
alert("沒有傳回值來");
}else{
document.getElementById("mytext").value=str;
}
}
</script>
</HEAD>
<BODY>
<input type="text" id="mytext">
<input type="button" value="button" onclick="newWin();">
</BODY>
</HTML>
b頁面代碼
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Page B </TITLE>
<script language="javascript">
function colseWin(){
var returnValue = document.getElementById("mytext").value.trim;
window.returnValue=returnValue;
window.close();
}
</script>
</HEAD>
<BODY>
<input type="text" id="mytext">
<input type="button" value="保存並關閉" onclick="colseWin();">
</BODY>
</HTML>
=======================================================
把兩個文件保存到同級目錄下就可以了.
I. 用Java如何實現界面的功能
新建一個窗口,然後實現一個關閉按鈕」窗口的功能
import java.awt.*;
import java.awt.event.*;
public class TestWindowEvent {
public static void main (String[] args) {
new Frame88 ("WindowAdapter");
}
}
class Frame88 extends Frame {
Frame88 (String s) {
super(s);
setBounds (300,300,200,70);
setLayout (null);
setVisible (true);
addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible (false);
System.exit(0);
}
} );
}
}