java用戶界面
① java編程 設計一個圖形用戶界面。界麵包括三個單選按鈕、兩個復選框、一個列表、一個文本區和一個按
程序如下:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
public class JFrameDemo extends JFrame implements ActionListener
{
private JPanel panel;
private JButton button;
private JTextArea textArea;
private JCheckBox musicBox;
private JCheckBox danceBox;
private JRadioButton hanButton;
private JRadioButton manButton;
private JRadioButton huiButton;
private ButtonGroup buttonGroup;
public JFrameDemo()
{
panel = new JPanel();
button = new JButton("確定");
textArea = new JTextArea(40,30);
musicBox = new JCheckBox("唱歌"橡滲);
danceBox = new JCheckBox("跳舞梁念脊"高輪);
huiButton = new JRadioButton("回族");
hanButton = new JRadioButton("漢族");
manButton = new JRadioButton("滿族");
buttonGroup = new ButtonGroup();
buttonGroup.add(huiButton);
buttonGroup.add(hanButton);
buttonGroup.add(manButton);
panel.setLayout(new FlowLayout(3));
panel.add(huiButton);
panel.add(hanButton);
panel.add(manButton);
panel.add(musicBox);
panel.add(danceBox);
panel.add(button);
panel.add(textArea);
add(panel);
setTitle("選擇興趣愛好");
setBounds(100, 100, 400, 280);
setResizable(false);
setVisible(true);
this.button.addActionListener(this);
}
public static void main(String[] args)
{
new JFrameDemo();
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == this.button)
{
String info = "";
if(this.huiButton.isSelected())
{
info += this.huiButton.getText() + "\n";
}
if(this.hanButton.isSelected())
{
info += this.hanButton.getText() + "\n";
}
if(this.manButton.isSelected())
{
info += this.manButton.getText() + "\n";
}
if(this.danceBox.isSelected())
{
info += this.danceBox.getText() + "\n";
}
if(this.musicBox.isSelected())
{
info += this.musicBox.getText() + "\n";
}
this.textArea.setText(info);
}
}
}
有問題歡迎提問,滿意請採納,謝謝!
② 用JAVA編寫一個用戶或注冊登錄界面。請哪位高手能夠寫下具體的代碼,謝謝
效果圖
<!DOCTYPEhtml>
<html>
<head>
<metacharset="UTF-8">
<title>先鋒圖書館管理系統-登錄</title>
<style>
*{
margin:0;
padding:0;
list-style:none;
}
#top{
width:1000px;
height:95px;
margin:0auto;
margin-top:25px;
}
#top_top{
width:1000px;
height:65px;
background:deepskyblue;
}
#top_top_left{
width:300px;
height:65px;
float:left;
}
#top_top_left>label{
width:200px;
height:65px;
color:white;
float:right;
}
#top_top_left>#a2{
padding-left:10px;
padding-top:20px;
font-size:16px;
}
#top_bottom{
width:1000px;
height:30px;
}
#top_bottom_left{
width:340px;
height:30px;
line-height:30px;
font-size:12px;
background:skyblue;
color:white;
text-indent:2em;
float:left;
}
#top_bottom_right{
width:660px;
height:30px;
line-height:30px;
font-size:12px;
color:blueviolet;
text-align:center;
float:right;
background:lightskyblue;
}
#content{
width:1000px;
height:600px;
margin:0auto;
background:#587FBA;
}
#content>#text{
width:1000px;
height:50px;
line-height:50px;
padding-top:100px;
font-size:36px;
font-family:"楷體";
font-weight:bold;
text-align:center;
}
#content>#login{
width:480px;
height:210px;
margin-top:20px;
margin-left:260px;
background:#85A0CB;
}
#content>#login>img{
float:left;
}
#content>#login>#select{
width:305px;
height:210px;
float:right;
}
#content>#login>#select>div{
width:230;
height:30px;
margin-left:30px;
}
#content>#login>#select>#d1{
margin-top:30px;
margin-bottom:3px;
}
#content>#login>#select>p{
font-size:14px;
margin-left:95px;
}
#bottom{
width:1000px;
height:35px;
line-height:35px;
margin:0auto;
background:deepskyblue;
text-align:center;
color:white;
}
</style>
</head>
<body>
<divid="top">
<divid="top_top">
<divid="top_top_left">
<imgsrc="img/test/a13.png"width="78px"height="65px"><labelid="a2">先鋒圖書館系統管理平台</label>
</div>
</div>
<divid="top_bottom">
<divid="top_bottom_left">當前位置:首頁>系統管理>登錄</div>
<divid="top_bottom_right">當前時間:<labelid="lable"></label></div>
</div>
</div>
<divid="content">
<divid="text">歡迎登錄先鋒圖書館管理系統</div>
<divid="login">
<imgsrc="img/test/a14.png"width="175px"height="210px"/>
<formid="select">
<divid="d1">用戶名: <inputtype="text"/></div>
<div>密 碼: <inputtype="password"/></div>
<p>
<inputtype="radio"name="user"value="read"/>讀者
<inputtype="radio"name="user"value="admin"/>管理員
</p><br/>
<p>
<inputtype="button"value="確定"style="width:50px;"onclick="put()"/>
<inputtype="reset"value="重置"style="width:50px;"/>
</p>
</form>
</div>
</div>
<divid="bottom">欣欣科技有限公司版權所有</div>
</body>
<scripttype="text/javascript"src="JQuery/jquery.js"></script>
<scripttype="text/javascript"src="js/GetCurrentTime.js"></script>
<script>
//驗證用戶名和密碼
functionput(){
vard=$("#select>div>input");//獲取用戶名和密碼
varname=d[0].value;
varpass=d[1].value;
varuser=null;
varr=document.getElementsByName("user");//獲取用戶類型
for(i=0;i<r.length;i++){
if(r[i].checked){
user=r[i].value;
}
}
//console.log(name+","+pass+","+user);//輸出測試
if(user==null){
window.alert("請選擇用戶類型!");
}elseif(user=="admin"&&name!="admin"){
window.alter("用戶名錯誤!");
}elseif(user=="admin"&&name=="admin"&&pass!="123456"){
window.alert("密碼錯誤!");
}elseif(name=="admin"&&pass=="123456"&&user=="admin"){
window.location.href="work_02_welcome.html";//在js中在本頁面中打開新鏈接
}else{
window.alert("用戶名錯誤");
}
}
</script>
</html>