JAVA的图形用户界面代码

JAVA的图形用户界面代码,第1张

package hao;

import javaawtBorderLayout;

import javaawtColor;

import javaawtDimension;

import javaawtGridLayout;

import javaioFile;

import javaxswingBorderFactory;

import javaxswingBox;

import javaxswingImageIcon;

import javaxswingJButton;

import javaxswingJComboBox;

import javaxswingJLabel;

import javaxswingJPanel;

import javaxswingJScrollPane;

import javaxswingJTextArea;

import javaxswingJTextPane;

import javaxswingtextBadLocationException;

import javaxswingtextSimpleAttributeSet;

import javaxswingtextStyleConstants;

import javaxswingtextStyledDocument;

public class ChatPanel extends JPanel {

private static final long serialVersionUID = 1L;

JButton send,record,saveRecord,image;

JTextArea inputArea;

JTextPane text;//注意用法

JComboBox fontName = null, fontSize = null, fontStyle = null, fontColor = null,fontBackColor = null;

public StyledDocument doc = null; JScrollPane scrollPane;JPanel textChat;

JButton music;

public ChatPanel() {

setLayout(new BorderLayout());

text = new JTextPane();

textsetEditable(false);

doc = textgetStyledDocument();//跟踪文本和写到该区域的位置

scrollPane = new JScrollPane(text);

//注意下面对JComboBox的巧用

String[] str_name = { "宋体", "黑体", "Dialog", "Gulim" };

String[] str_Size = { "12", "14", "18", "22", "30", "40" };

String[] str_Style = { "常规", "斜体", "粗体", "粗斜体" };

String[] str_Color = { "黑色", "红色", "蓝色", "**", "绿色" };

String[] str_BackColor = { "无色", "灰色", "淡红", "淡蓝", "淡黄", "淡绿" };

fontName = new JComboBox(str_name);

fontSize = new JComboBox(str_Size);

fontStyle = new JComboBox(str_Style);

fontColor = new JComboBox(str_Color);

fontBackColor = new JComboBox(str_BackColor);

fontNamesetBackground(new Color(255,153,255));

fontSizesetBackground(new Color(255,153,255));

fontStylesetBackground(new Color(255,153,255));

fontColorsetBackground(new Color(255,153,255));

fontBackColorsetBackground(new Color(255,153,255));

Box box = BoxcreateVerticalBox();//创建一个可以容纳多个Box组件的Box

Box box_1 = BoxcreateHorizontalBox();

Box box_2 = BoxcreateHorizontalBox();

Box box_4 = BoxcreateHorizontalBox();

boxadd(box_1);

boxadd(box_2);

boxadd(box_4);

JLabel b1= new JLabel("字体~~"), b2 = new JLabel("样式~~"),b3 = new JLabel("字号~~"),b4 = new JLabel("颜色~~"),b5 = new JLabel("背景~~");

b1setBackground(new Color(255,153,255));

b2setBackground(new Color(255,153,255));

b3setBackground(new Color(255,153,255));

b4setBackground(new Color(255,153,255));

b5setBackground(new Color(255,153,255));

box_1add(b1);

box_1add(fontName);

box_1add(BoxcreateHorizontalStrut(8));

box_1add(b2);

box_1add(fontStyle);

box_1add(BoxcreateHorizontalStrut(8));

box_1add(b3);

box_1add(fontSize);

box_2add(BoxcreateHorizontalStrut(8));

box_2add(b4);

box_2add(fontColor);

box_2add(BoxcreateHorizontalStrut(8));

box_4add(b5);

box_4add(fontBackColor);

textChat = new JPanel();

textChatsetLayout(new BorderLayout());

textChatsetBackground(new Color(255,153,255));

inputArea = new JTextArea(3, 20);

inputAreasetLineWrap(true); //设置文本区的换行策略。88888

send = new JButton("发送");

record=new JButton("显示记录");

saveRecord=new JButton("储存记录");

image=new JButton("表情");

sendsetBackground(new Color(255,153,255));

recordsetBackground(new Color(255,153,255));

saveRecordsetBackground(new Color(255,153,255));

imagesetBackground(new Color(255,153,255));

Box box_3 = BoxcreateHorizontalBox();

box_3add(send); box_3add(BoxcreateHorizontalStrut(8));//设置按钮间距888

box_3add(record); box_3add(BoxcreateHorizontalStrut(8)); //设置按钮间距888

box_3add(saveRecord); box_3add(BoxcreateHorizontalStrut(8));//设置按钮间距888

box_3add(image);

boxsetBorder(BorderFactorycreateLineBorder(new Color(102,102,0),5));//设置Box的边框线

box_3setBorder(BorderFactorycreateLineBorder(new Color(102,102,0),5));

textChatadd(box,BorderLayoutNORTH);

textChatadd(inputArea,BorderLayoutCENTER);

textChatadd(box_3, BorderLayoutSOUTH);

inputArearequestFocus(true);

inputAreasetBorder(BorderFactorycreateLineBorder(new Color(102,102,0),5));//设置输入窗口边框线

textsetBorder(BorderFactorycreateLineBorder(new Color(102,102,0),8));//设置输入窗口边框线

JPanel audioPanel = new JPanel();//最上面的边框

audioPanelsetBackground(new Color(255,153,255));

audioPanelsetLayout(new GridLayout(1,1));

music = new JButton("想听就听");

musicsetPreferredSize(new Dimension(320,50));

musicsetBorder(BorderFactorycreateLineBorder(ColorBLACK,10));//设置输入窗口边框线

audioPaneladd(music);

add(audioPanel, BorderLayoutNORTH);

add(scrollPane,BorderLayoutCENTER);

add(textChat, BorderLayoutSOUTH);

}

void insertIcon(ImageIcon image) {

textsetCaretPosition(docgetLength());

textinsertIcon(image);

insert(new MessageStyle());///

}

public void insert(MessageStyle attrib) {

try {

docinsertString(docgetLength(), attribgetText() + "\n", attribgetAttrSet());//写完后接着换行

} catch (BadLocationException e) {

eprintStackTrace();

}

}

public MessageStyle getMessageStyle(String line) {

MessageStyle att = new MessageStyle();

attsetText(line);

attsetName((String) fontNamegetSelectedItem());

attsetSize(IntegerparseInt((String) fontSizegetSelectedItem()));

String temp_style = (String) fontStylegetSelectedItem();

if (temp_styleequals("常规")) {

attsetStyle(MessageStyleGENERAL);

}

else if (temp_styleequals("粗体")) {

attsetStyle(MessageStyleBOLD);

}

else if (temp_styleequals("斜体")) {

attsetStyle(MessageStyleITALIC);

}

else if (temp_styleequals("粗斜体")) {

attsetStyle(MessageStyleBOLD_ITALIC);

}

String temp_color = (String) fontColorgetSelectedItem();

if (temp_colorequals("黑色")) {

attsetColor(new Color(0, 0, 0));

}

else if (temp_colorequals("红色")) {

attsetColor(new Color(255, 0, 0));

}

else if (temp_colorequals("蓝色")) {

attsetColor(new Color(0, 0, 255));

}

else if (temp_colorequals("**")) {

attsetColor(new Color(255, 255, 0));

}

else if (temp_colorequals("绿色")) {

attsetColor(new Color(0, 255, 0));

}

String temp_backColor = (String) fontBackColorgetSelectedItem();

if (!temp_backColorequals("无色")) {

if (temp_backColorequals("灰色")) {

attsetBackColor(new Color(200, 200, 200));

}

else if (temp_backColorequals("淡红")) {

attsetBackColor(new Color(255, 200, 200));

}

else if (temp_backColorequals("淡蓝")) {

attsetBackColor(new Color(200, 200, 255));

}

else if (temp_backColorequals("淡黄")) {

attsetBackColor(new Color(255, 255, 200));

}

else if (temp_backColorequals("淡绿")) {

attsetBackColor(new Color(200, 255, 200));

}

}

return att;

}

}

<%@language=vbscript codepage=936 %>

<%

option explicit

'强制浏览器重新访问服务器下载页面,而不是从缓存读取页面

ResponseBuffer = True

ResponseExpires = -1

ResponseExpiresAbsolute = Now() - 1

ResponseExpires = 0

ResponseCacheControl = "no-cache"

'主要是使随机出现的数字随机

%>

<html>

<head>

<title>管理员登录</title>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<link rel="stylesheet" href="Admin_Stylecss">

<script language=javascript>

function SetFocus()

{

if (documentLoginUserNamevalue=="")

documentLoginUserNamefocus();

else

documentLoginUserNameselect();

}

function CheckForm()

{

if(documentLoginUserNamevalue=="")

{

alert("请输入用户名!");

documentLoginUserNamefocus();

return false;

}

if(documentLoginPasswordvalue == "")

{

alert("请输入密码!");

documentLoginPasswordfocus();

return false;

}

//if (documentLoginCheckCodevalue==""){

// alert ("请输入您的验证码!");

// documentLoginCheckCodefocus();

// return(false);

}

}

</script>

</head>

<body onLoad="SetFocus();">

<p> </p>

<form name="Login" action="Admin_ChkLoginasp" method="post" target="_parent" onSubmit="return CheckForm();">

<table width="300" border="0" align="center" cellpadding="5" cellspacing="0" class="border" >

<tr class="title">

<td colspan="2" align="center"> <strong>管理员登录</strong></td>

</tr>

<tr>

<td height="120" colspan="2" class="tdbg">

<table width="250" border="0" cellspacing="8" cellpadding="0" align="center">

<tr>

<td align="right">用户名称:</td>

<td><input name="UserName" type="text" id="UserName2" size="23" maxlength="20"></td>

</tr>

<tr>

<td align="right">用户密码:</td>

<td><input name="Password" type="password" size="23" maxlength="20"></td>

</tr>

<tr>

<td align="right">验 证 码:</td>

<td><input name="CheckCode" size="15" maxlength="6">

1109 </td>

</tr>

<tr>

<td colspan="2"> <div align="center">

<input type="submit" name="Submit" value=" 确认 ">

<input name="reset" type="reset" id="reset" value=" 清除 ">

<br>

</div></td>

</tr>

</table>

</td>

</tr>

</table>

<p align="center">后台管理页面需要屏幕分辨率为 <font color="#FF0000"><strong>1024768</strong></font>

或以上才能达到最佳浏览效果!<br>

需要浏览器为<strong><font color="#FF0000"> </font></strong><font color="#FF0000"><strong>IE55</strong></font>

或以上版本才能正常运行!!!</p>

</form>

</body>

</html>

这个是处理表单的页面,其实如果按照你说的,只有一个用户名的话,那就不用数据库咯。满简单的。

<%

AdminName=request("AdminName")

Password=request("Password")

if AdminName<>"制作" then

responsewrite"<SCRIPT language=JavaScript>alert('用户名不正确!');"

responsewrite"javascript:historygo(-1)</SCRIPT>"

else

responseredirect"qindayuancom/vcckxp/215165htm"

end if

if Password<>"0123456789" then

responsewrite"<SCRIPT language=JavaScript>alert('密码错误!');"

responsewrite"javascript:historygo(-1)</SCRIPT>"

else

responseredirect"qindayuancom/vcckxp/215165htm"

end if

%>

这样子你试试看,表单的用户名文本框name用AdminName表示,密码用password。试试看吧,如果你觉得这代码不好的话,不用评答案也行,我只是给你一个参考。

资源选项卡,插入对话框,拖控件。两个静态文本:用户名、密码。两个文本框:用户名,密码(属性卡里style选择 密码,输入的密码会显示),两个按钮 确定、取消。

2给此对话框添加类CLOGIN

3在类的Cpp文件里添加代码

//动画显示登录奥~

#define AW_CENTER 0x00000010 //动画#define AW_HIDE 0x00010000 //隐藏

BOOL CLOGIN::OnInitDialog()

{

CDialog::OnInitDialog();

//如果用到数据库判断用户名和密码的话这里要添加打开数据库,比对用户名和密码的代码

//不连接数据库的话 用IF Else判断用户名密码是不是对就行

//动画显示登录框

CenterWindow();

DWORD dwStyle = AW_CENTER;

HINSTANCE hInst = LoadLibrary("User32DLL");

typedef BOOL(WINAPI MYFUNC(HWND,DWORD,DWORD));

MYFUNC AnimateWindow;

AnimateWindow=(MYFUNC )::GetProcAddress(hInst,"AnimateWindow");

AnimateWindow(this->m_hWnd,1000,dwStyle);

FreeLibrary(hInst);

return TRUE;

}

不用MFC方法的话,你的对话框 控件啥的都得动态添加,用代码实现,那样太折腾了

在搜狗里面搜孙鑫老师的教学视频 在HTML这一章节中他好像有讲过 当然 你得慢慢的从头至尾细细品味 好像也就只是涉及到表单的制作吧 这是我从一个网站上复制的

wwwadmin5com/html HTML表单(Form)是HTML的一个重要部分,主要用于采集和提交用户输入的信息。

举个简单的例子,一个让用户输入姓名的HTML表单(Form)。示例代码如下:

<form action="http://wwwadmin5com/html/asdocs/html_tutorials/yournameasp" method="get">

请输入你的姓名:

<input type="text" name="yourname">

<input type="submit" value="提交">

</form>

演示示例

学习HTML表单(Form)最关键要掌握的有三个要点:

表单控件(Form Controls)

Action

Method

先说表单控件(Form Controls),通过HTML表单的各种控件,用户可以输入文字信息,或者从选项中选择,以及做提交的操作。比如上面的例句里,input type= "text"就是一个表单控件,表示一个单行输入框。

用户填入表单的信息总是需要程序来进行处理,表单里的action就指明了处理表单信息的文件。比如上面例句里的http://wwwadmin5com/html/asdocs/html_tutorials/yournameasp。

至于method,表示了发送表单信息的方式。method有两个值:get和post。get的方式是将表单控件的name/value信息经过编码之后,通过URL发送(你可以在地址栏里看到)。而post则将表单的内容通过http发送,你在地址栏看不到表单的提交信息。那什么时候用get,什么时候用post呢?一般是这样来判断的,如果只是为取得和显示数据,用get;一旦涉及数据的保存和更新,那么建议用post。

HTML表单(Form)常用控件(Controls)

HTML表单(Form)常用控件有:

表单控件(Form Contros) 说明

input type="text" 单行文本输入框

input type="submit" 将表单(Form)里的信息提交给表单里action所指向的文件

input type="checkbox" 复选框

input type="radio" 单选框

select 下拉框

textArea 多行文本输入框

input type="password" 密码输入框(输入的文字用表示)

表单控件(Form Control):单行文本输入框(input type="text")

单行文本输入框允许用户输入一些简短的单行信息,比如用户姓名。例句如下:

<input type="text" name="yourname">

演示示例

表单控件(Form Control):复选框(input type="checkbox")

复选框允许用户在一组选项里,选择多个。示例代码:

<input type="checkbox" name="fruit" value ="apple">苹果<br>

<input type="checkbox" name="fruit" value ="orange">桔子<br>

<input type="checkbox" name="fruit" value ="mango">芒果<br>

演示示例

用checked表示缺省已选的选项。

<input type="checkbox" name="fruit" value ="orange" checked>桔子<br>

演示示例

表单控件(Form Control):单选框(input type="radio")

使用单选框,让用户在一组选项里只能选择一个。示例代码:

<input type="radio" name="fruit" value = "Apple">苹果<br>

<input type="radio" name="fruit" value = "Orange">桔子<br>

<input type="radio" name="fruit" value = "Mango">芒果<br>

演示示例

用checked表示缺省已选的选项。

<input type="radio" name="fruit" value = "Orange" checked>桔子<br>

演示示例

表单控件(Form Control):下拉框(select)

下拉框(Select)既可以用做单选,也可以用做复选。单选例句如下:

<select name="fruit" >

<option value="apple">苹果

<option value="orange">桔子

<option value="mango">芒果

</select>

演示示例

如果要变成复选,加muiltiple即可。用户用Ctrl来实现多选。例句:

<select name="fruit" multiple>

演示示例

用户还可以用size属性来改变下拉框(Select)的大小。

演示示例

表单控件(Form Control):多行输入框(textarea)

多行输入框(textarea)主要用于输入较长的文本信息。例句如下:

<textarea name="yoursuggest" cols ="50" rows = "3"></textarea>

其中cols表示textarea的宽度,rows表示textarea的高度。

演示示例

表单控件(Form Control):密码输入框(input type="password")

密码输入框(input type="password")主要用于一些保密信息的输入,比如密码。因为用户输入的时候,显示的不是输入的内容,而是黑点符号。。例句如下:

<input type="password" name="yourpw">

演示示例

表单控件(Form Control):提交(input type="submit")

通过提交(input type=submit)可以将表单(Form)里的信息提交给表单里action所指向的文件。例句如下:

<input type="submit" value="提交">

演示示例

表单控件(Form Control):提交(input type="image")

input type=image 相当于 input type=submit,不同的是,input type=image 以一个作为表单的提交按钮,其中 src 属性表示的路径。

<input type="image" src ="images/icons/gogif"

alt = "提交" NAME="imgsubmit">

演示示例

如何编写 ASP 网页获取 HTML 表单的提交信息,请参见教程:ASP和HTML表单

欢迎分享,转载请注明来源:品搜搜测评网

原文地址:https://pinsoso.cn/meirong/2194313.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-11-16
下一篇2023-11-16

随机推荐

  • 莱珀妮鱼子酱精华真假

    莱珀妮鱼子酱精华是一款非常受欢迎的美容产品,它所使用的成分包括鲟鱼子和珍珠等天然提取物,被誉为能够改善肌肤质量、提升肌肤光泽度的神奇产品。对于这款产品,关心它真假问题的人们很多,我们从以下几个角度来回答大家的疑问。我们需要知道莱珀妮鱼子酱精

    2024-04-15
    26900
  • 精华露的正确使用步骤

    精华液和精华液本质上是一样的,所以用的顺序是一样的,爽肤水之后,乳液之前。但也有一些品牌的精华比较特殊,在爽肤水之前使用,也就是洁面后的第一步,比如:秘密美白柔滑精华、雪花秀保湿精华。1洗脸:洗面奶、面霜或慕思是最常用的洗脸方法。2涂抹爽肤

    2024-04-15
    25100
  • 张柏芝代言的羊奶霜质量怎么样

    好。张柏芝是一个非常遵纪守法和讲诚信的销售团队。他们用羊奶粉制成的羊奶霜,非常受消费者的欢迎,因为他们的成分非常优秀,款式非常齐全,营养非常全面,对年轻女性有非常好的护肤效果。性价比也非常高。我自己用艾璐卡羊奶霜的时候,一指甲盖大小就足够啦

    2024-04-15
    10100
  • 最好用的平价美白精华 美白淡斑精华推荐

    在改善皮肤色调上,美白精华是不能缺席的。我在上高中的时候就开始使用美白精华,而且这多年也总结出一些经验。我整理出了五款价格亲民,效果很好的美白精华淡斑产品,款款都是实力派,效果不比大牌差!1、自然堂凝时小紫瓶精华液参考价格:115元这款精华

    2024-04-15
    8600
  • 混合肌精华液推荐 8款必推精华液

    在这炎热的夏天,很容易缺油又缺水的,混合肌T字部位较容易出油、而两颊也会比较干燥,所以常常皮肤会油水不平衡!应该不少混合肌们在挑选保养品的时候,很常会面临到『想改善又不知道从何着手』、『哪一款不会太油也不会太干』等等这些恼人的问题!面对琳

    2024-04-15
    15800
  • 大蒜美白效果怎么样?与欧露莲蒜肽美容是一样的吗?

        大蒜由于强烈的气味,往往不受年轻人的青睐,但是对于保养皮肤来说,大蒜有着不可替代的作用,大蒜对皮肤的作用很大,包括:美白、排毒、补水、保湿等等。所以在生活中要适当的吃一些大蒜。1.大蒜可以美白肌肤大蒜中的维生素C及类胡萝卜素的含量很

    2024-04-15
    17000
  • 浙江省绍兴市上虞区哪里有卖绿嫩化妆品

    绍兴市上虞区百官街道美女开化妆品店。绍兴市上虞区百官街道美女开化妆品店,成立于2009年,位于浙江省绍兴市,是一家以从事居民服务业为主的企业,卖绿嫩化妆品,主要经营化妆品批发零售、美容服务。绿嫩护肤品的加盟具体流程如下:1、在绿嫩护肤品官网

    2024-04-15
    15500

发表评论

登录后才能评论
保存