十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
你要先學(xué)會截圖哦,你發(fā)的看不清楚,重新寫了一個你參考參考!
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、小程序定制開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了高臺免費(fèi)建站歡迎大家使用!
import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class Day30A extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel labelName,labelId,labelPass,labelMoney,labelSelect,labelCar;
private JComboBoxString jcb;
private JPanel jp1,jp2,jp3,jp4,jp5,jp6,jp7;
private ButtonGroup btg;
private JRadioButton jr1,jr2;
Day30A(){
this.setTitle("注冊賬戶");
this.setLayout(new GridLayout(7,1));
this.setSize(300,280);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
init();
this.setVisible(true);
}
private void init() {
String str="卡片類型1,卡片類型2,卡片類型3,卡片類型4,卡片類型5";
jcb=new JComboBox(str.split(","));
labelId=new JLabel("賬號: ");
labelName=new JLabel("姓名: ");
labelPass=new JLabel("密碼: ");
labelMoney=new JLabel("開戶金額:");
labelSelect=new JLabel("存款類型:");
labelCar=new JLabel("卡片類型:");
addFun1();
addFun2();
}
private void addFun2() {
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.add(jp4);
this.add(jp5);
this.add(jp6);
this.add(jp7);
}
private void addFun1() {
jp1=new JPanel();
jp1.add(labelId);
jp1.add(new JTextField(15));
jp2=new JPanel();
jp2.add(labelName);
jp2.add(new JTextField(15));
jp3=new JPanel();
jp3.add(labelPass);
jp3.add(new JTextField(15));
jp4=new JPanel();
jp4.add(labelMoney);
jp4.add(new JTextField(13));
jp5=new JPanel();
jp5.add(labelSelect);
btg=new ButtonGroup();
jr1=new JRadioButton("定期");
jr2=new JRadioButton("活期",true);
btg.add(jr1);
btg.add(jr2);
jp5.add(jr1);
jp5.add(jr2);
jp6=new JPanel();
jp6.add(labelCar);
jp6.add(jcb);
jp7=new JPanel();
jp7.add(new JButton("確定"));
jp7.add(new JButton("取消"));
}
public static void main(String[] args) {
new Day30A();
}
}
遼主臨軒的分享
分享
java程序模擬qq登錄界面的代碼
java程序如何實(shí)現(xiàn)登錄、記住密碼、自動登錄等功能!
package dyno.swing.beans.qq;
import javax.swing.*;
import javax.swing.event.MouseInputListener;
import org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel;
/*import org.jvnet.substance.skin.SubstanceModerateLookAndFeel;
import org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel;*/
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
public class QQLogin extends JFrame implements MouseInputListener,ActionListener{
JLabel guanggao,beijing,wenzi,shezhi,zhanghaowb,qq1,dengluzhuangtai;
// JTextField zhanghao;
JPopupMenu haoma;
JComboBox zhanghao;
JPasswordField mima;
JCheckBox jizhumima,zidongdenglu;
JButton denglu,chashamuma;
JProgressBar jpb;
SimThread activity;
Timer activityMonitor;
String name,qq;
Socket s;
public QQLogin()
{
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (ClassNotFoundException e1) {
// TODO 自動生成 catch 塊
e1.printStackTrace();
} catch (InstantiationException e1) {
// TODO 自動生成 catch 塊
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO 自動生成 catch 塊
e1.printStackTrace();
} catch (UnsupportedLookAndFeelException e1) {
// TODO 自動生成 catch 塊
e1.printStackTrace();
}
chashamuma = new JButton("查殺木馬");
chashamuma.setBounds(240, 155,85, 20);
this.add(chashamuma);
jpb = new JProgressBar();
jpb.setStringPainted(true);
jpb.setBounds(100, 240, 200, 15);
this.add(jpb);
chashamuma.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jpb.setMaximum(1000);//設(shè)置進(jìn)度欄的最大值
activity=new SimThread(1000);
activity.start();//啟動線程
activityMonitor.start();//啟動定時器
chashamuma.setEnabled(false);//禁止按鈕
}
});
activityMonitor=new Timer(100,new ActionListener(){//每0.5秒執(zhí)行一次
public void actionPerformed(ActionEvent e){//以下動作將在事件調(diào)度線程中運(yùn)行,十分安全
int current=activity.getCurrent();//得到線程的當(dāng)前進(jìn)度
jpb.setValue(current);//更新進(jìn)度欄的值
if(current==activity.getTarget()){//如果到達(dá)目標(biāo)值
activityMonitor.stop();//終止定時器
chashamuma.setEnabled(true);//激活按鈕
}
}
});
dengluzhuangtai = new JLabel(new ImageIcon("zaixianzhuangtai.jpg"));
dengluzhuangtai.setBounds(75, 145, 35, 30);
this.add(dengluzhuangtai);
dengluzhuangtai.addMouseListener(this);
denglu = new JButton("登錄");
denglu.setBounds(140, 155, 80, 20);
this.add(denglu);
this.setAlwaysOnTop(true);
zidongdenglu = new JCheckBox("自動登錄");
zidongdenglu.setBounds(200, 190, 100, 30);
this.add(zidongdenglu);
jizhumima = new JCheckBox("記住密碼");
jizhumima.setBounds(100, 190, 100, 30);
// jizhumima.setBackground(new Color(228, 244, 255));
this.add(jizhumima);
haoma = new JPopupMenu();
/* zhanghao = new JTextField(20);
zhanghao.setBounds(120, 78, 135, 20);
zhanghao.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.WHITE));
zhanghao.setFont(new Font("宋體",Font.PLAIN,13));
this.add(zhanghao);*/
// zhanghaowb = new JLabel(new ImageIcon("2.png"));
// zhanghaowb.setBounds(90, 73, 194, 31);
// jiantou = new JLabel(new ImageIcon("baijiantou.png"));
// jiantou.setBounds(256, 78, 23, 21);
// jiantou.addMouseListener(this);
// this.add(jiantou);
// this.add(zhanghaowb);
chashamuma.addActionListener(this);
mima = new JPasswordField();
mima.setEchoChar('*');
mima.setFont(new Font("宋體",Font.PLAIN,13));
mima.setBounds(100, 113, 150, 20);
this.add(mima);
zhanghao = new JComboBox();
zhanghao.setEditable(true);
zhanghao.setBounds(100, 78, 150, 20);
zhanghao.setFont(new Font("宋體",Font.PLAIN,13));
this.add(zhanghao);
guanggao = new JLabel(new ImageIcon("guanggao.gif"));
guanggao.setBounds(0, 0, 334, 64);
beijing = new JLabel(new ImageIcon("beijing.jpg"));
beijing.setBounds(0, 64, 334, 154);
wenzi = new JLabel(new ImageIcon("wenzi.jpg"));
wenzi.setBounds(30, 75, 50, 100);
denglu.addActionListener(this);
// zhanghaowb.addMouseListener(this);
// zhanghao.addMouseListener(this);
this.add(wenzi);
this.add(beijing);
this.setLayout(null);
this.add(guanggao);
this.setVisible(true);
this.setDefaultCloseOperation(3);
this.setSize(340, 250);
this.setLocationRelativeTo(null);
}
public static void main(String[] args) {
/*JFrame.setDefaultLookAndFeelDecorated(true);
try {
UIManager.setLookAndFeel(new SubstanceOfficeBlue2007LookAndFeel()) ;
UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel");
} catch (Exception e) {
System.out.println("Substance Raven Graphite failed to initialize");
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
QQLogin w = new QQLogin();
w.setVisible(true);
}
});*/
new QQLogin();
}
public void mouseClicked(MouseEvent e) {
// TODO 自動生成方法存根
}
public void mouseEntered(MouseEvent e) {
if(e.getSource() == dengluzhuangtai)
{
dengluzhuangtai.setIcon(new ImageIcon("zaixianzhuangtaidian.jpg"));
}
}
public void mouseExited(MouseEvent e) {
if(e.getSource() == dengluzhuangtai)
{
dengluzhuangtai.setIcon(new ImageIcon("zaixianzhuangtai.jpg"));
}
}
public void mousePressed(MouseEvent e) {
// TODO 自動生成方法存根
}
public void mouseReleased(MouseEvent e) {
// TODO 自動生成方法存根
}
public void mouseDragged(MouseEvent e) {
// TODO 自動生成方法存根
}
public void mouseMoved(MouseEvent e) {
// TODO 自動生成方法存根
}
public class liaotianchuangkou
{
}
class SimThread extends Thread{//線程類
private int current;//進(jìn)度欄的當(dāng)前值
private int target;//進(jìn)度欄的最大值
public SimThread(int t){
current=0;
target=t;
}
public int getTarget(){
return target;
}
public int getCurrent(){
return current;
}
public void run(){//線程體
try{
while (currenttarget !interrupted()){//如果進(jìn)度欄的當(dāng)前值小于目標(biāo)值并且線程沒有被中斷
sleep(10);
current++;
if(current == 700)
{
sleep(3000);
}
else if(current == 730)
{
sleep(1000);
}
}
}catch (InterruptedException e){}
}
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == chashamuma)
{
this.setBounds(300, 300, 340, 300);
}
else if(e.getSource() == denglu)
{
String zh = (String) zhanghao.getSelectedItem();
System.out.println(zhanghao.getSelectedItem());
// System.out.println(zhanghao.getItemAt(0));
char [] str = mima.getPassword();
String mima = String.valueOf(str);;
System.out.println(mima);
// Sql login = new Sql();
// if(login.login(zh,mima))
// {
try {
s = new Socket("127.0.0.1",8888);
System.out.println(s);
PrintWriter pw;
Scanner sc;
pw = new PrintWriter(s.getOutputStream(),true);
sc = new Scanner(s.getInputStream());
String str2 = "login#289872400198724#"+zh+"#289872400198724#"+mima;
System.out.println(str2);
pw.println(str2);
String str3 = sc.nextLine();
String yanzheng[] = str3.split("#");
System.out.println(str3);
if(yanzheng[0].equals("true"))
{
System.out.println("登陸成功!");
name = yanzheng[1];
qq = yanzheng[2];
// this.setVisible(false);
// Thread.sleep(5000);
System.out.println("woao"+name);
System.out.println("woai"+qq);
Logined logined = new Logined(name,qq);
this.setVisible(false);
}
else
{
JOptionPane.showMessageDialog(this, "用戶名或密碼錯誤!", "用戶名或密碼錯誤!", 0);
}
} catch (UnknownHostException e2) {
// TODO 自動生成 catch 塊
e2.printStackTrace();
} catch (IOException e2) {
// TODO 自動生成 catch 塊
e2.printStackTrace();
}
/*try {
login.rs = login.stat.executeQuery("select * from qquser where username='"+zh+"' and password = '"+mima+"'");
boolean flag = login.rs.next();
if(flag == true)
{
name = login.rs.getString("name");
qq = login.rs.getString("username");
}
else
{
}*/
// } catch (SQLException e1) {
// TODO 自動生成 catch 塊
// e1.printStackTrace();
// }
}
else
{
JOptionPane.showMessageDialog(this, "用戶名或密碼錯誤", "輸入錯誤", 0);
}
// this.setVisible(false);
//new Logined();
}
}
如果是想讓普通用戶執(zhí)行哪個程序,可以設(shè)置 S 權(quán)限位,如
#chmod +s /sbin/reboot
還有一種方法,編輯兩個腳本,
一個由/etc/rc.local啟動,讀取并執(zhí)行 /tmp/fifofile323 (使用 mkfifo創(chuàng)建的管道文件)的命令,
然后使用普通用戶向管道輸送命令,使得需要root用戶執(zhí)行的命令可以用普通用戶來執(zhí)行。
之前,也考慮過使用單點(diǎn)登錄,幾經(jīng)嘗試之后還是放棄了。
我習(xí)慣使用Java,本能地開始尋找Java的解決方法,在Google中輸入"Java自動登錄"、"Java網(wǎng)頁模擬登錄"、"JavaPost登錄",結(jié)果倒是不少,內(nèi)容也差不多,我嘗試很多次終究也沒有達(dá)到我預(yù)期的目標(biāo)。后來,我都不知道這些代碼應(yīng)該在jsp頁面中執(zhí)行還是在c/s結(jié)構(gòu)的程序中執(zhí)行。但這些代碼確實(shí)管用。 我們先分析一下代碼: URLurl=newURL(surl); URLConnectionconn=url.openConnection(); conn.setDoOutput(true); OutputStreamWriterout=newOutputStreamWriter(conn.getOutputStream()); Stringstr="username=yournamepassword=123456"; out.write(str); out.flush(); out.close(); 到這里,如果在C/S結(jié)構(gòu)中,且參數(shù)正確,程序能夠成功登錄到這個oa系統(tǒng),要看到結(jié)果,你可以通過下面的代碼將系統(tǒng)服務(wù)器返回的結(jié)果System.out.println()出來。 Stringsling=""; Stringscontent=""; BufferedReaderin=newBufferedReader(newInputStreamReader(conn.getInputStream(),"UTF-8")); while((sling=in.readLine())!=null) scontent+=in+"\r\n"; System.out.println(scontent); 在C/S結(jié)構(gòu)下,可以到得到控制臺輸出了返回值,從返回內(nèi)容里可以看出程序已經(jīng)成功登錄,但要是把這個網(wǎng)址瀏覽器打開,還是得重新登錄,問題沒有得到根本解決。如果只是惡意注冊,到這里應(yīng)該就達(dá)到目的了。 看樣子C/S結(jié)構(gòu)下不容易實(shí)現(xiàn)網(wǎng)頁程序自動登錄,除非你在C/S程序中內(nèi)嵌一個瀏覽器,直接在這個瀏覽器中自動訪問系統(tǒng),應(yīng)該沒有別的方法,主要問題在于我們沒有辦法共享Session. 為了便于共享Session,我們只能在瀏覽器中實(shí)現(xiàn)網(wǎng)頁自動登錄,通過上面的代碼在jsp頁面中測試,達(dá)不到預(yù)期目標(biāo)。 網(wǎng)頁自動登錄,就是希望程序自動填充用戶名和密碼,然后以Post方式提交給登錄頁面的Form所指向的action頁面或方法。我將系統(tǒng)的登錄頁面的源代碼保存成一個網(wǎng)頁,然后在username和password文本框中設(shè)置默認(rèn)值,然后通過這網(wǎng)頁登錄系統(tǒng),測試后,發(fā)現(xiàn)可行。接下來,你可能已經(jīng)想到了解決方法。 我們可以通過url.openConnection()建立連接,將返回的scontent打印出來,然后接著打印以下代碼: out.println("\r\n"); out.println("document.getElementsByName(\"username\")[0].value=yourname;\r\n"); out.println("document.getElementsByName(\"password\")[0].value=123456;\r\n"); out.println("document.forms[0].submit();\r\n"); out.println("\r\n"); 原理很簡單,通過login.jsp將登錄頁面的全部源代碼寫在當(dāng)前頁面,然后使用javascript腳本將用戶名和密碼的值填充上,最后提交表單。這樣中,終于實(shí)現(xiàn)了自動登錄的目標(biāo)?,F(xiàn)在我通過一個特殊的網(wǎng)址,就可以自動訪問這個oa了。 你可能注意到參數(shù)url,他的值是經(jīng)過加密的,內(nèi)容是用戶名和密碼。當(dāng)然,你也可以加上有效期,即在有效期內(nèi)這個鏈接才是有效的,才可以實(shí)現(xiàn)自動登錄。
希望能解決您的問題。
概述
具體框架使用jframe,文本框組件:JTextField;密碼框組件:JPasswordField;標(biāo)簽組件:JLabel;復(fù)選框組件:JCheckBox;單選框組件:JRadioButton;按鈕組件JButton。
登錄界面:
代碼實(shí)例
import javax.swing.*;
import java.awt.*; ? //導(dǎo)入必要的包
public class denglu extends JFrame{
JTextField jTextField ;//定義文本框組件
JPasswordField jPasswordField;//定義密碼框組件
JLabel jLabel1,jLabel2;
JPanel jp1,jp2,jp3;
JButton jb1,jb2; //創(chuàng)建按鈕
public denglu(){
jTextField = new JTextField(12);
jPasswordField = new JPasswordField(13);
jLabel1 = new JLabel("用戶名");
jLabel2 = new JLabel("密碼");
jb1 = new JButton("確認(rèn)");
jb2 = new JButton("取消");
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
//設(shè)置布局
this.setLayout(new GridLayout(3,1));
jp1.add(jLabel1);
jp1.add(jTextField);//第一塊面板添加用戶名和文本框
jp2.add(jLabel2);
jp2.add(jPasswordField);//第二塊面板添加密碼和密碼輸入框
jp3.add(jb1);
jp3.add(jb2); //第三塊面板添加確認(rèn)和取消
// ? ? ? ?jp3.setLayout(new FlowLayout()); ?//因?yàn)镴Panel默認(rèn)布局方式為FlowLayout,所以可以注銷這段代碼.
this.add(jp1);
this.add(jp2);
this.add(jp3); ?//將三塊面板添加到登陸框上面
//設(shè)置顯示
this.setSize(300, 200);
//this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setTitle("登陸");
}
public static void main(String[] args){
new denglu();
}
}
拓展內(nèi)容
java swing包
Swing 是一個為Java設(shè)計(jì)的GUI工具包。
Swing是JAVA基礎(chǔ)類的一部分。
Swing包括了圖形用戶界面(GUI)器件如:文本框,按鈕,分隔窗格和表。
Swing提供許多比AWT更好的屏幕顯示元素。它們用純Java寫成,所以同Java本身一樣可以跨平臺運(yùn)行,這一點(diǎn)不像AWT。它們是JFC的一部分。它們支持可更換的面板和主題(各種操作系統(tǒng)默認(rèn)的特有主題),然而不是真的使用原生平臺提供的設(shè)備,而是僅僅在表面上模仿它們。這意味著你可以在任意平臺上使用JAVA支持的任意面板。輕量級組件的缺點(diǎn)則是執(zhí)行速度較慢,優(yōu)點(diǎn)就是可以在所有平臺上采用統(tǒng)一的行為。
概念解析:
JFrame?– java的GUI程序的基本思路是以JFrame為基礎(chǔ),它是屏幕上window的對象,能夠最大化、最小化、關(guān)閉。
JPanel?– Java圖形用戶界面(GUI)工具包swing中的面板容器類,包含在javax.swing 包中,可以進(jìn)行嵌套,功能是對窗體中具有相同邏輯功能的組件進(jìn)行組合,是一種輕量級容器,可以加入到JFrame窗體中。。
JLabel?– JLabel 對象可以顯示文本、圖像或同時顯示二者。可以通過設(shè)置垂直和水平對齊方式,指定標(biāo)簽顯示區(qū)中標(biāo)簽內(nèi)容在何處對齊。默認(rèn)情況下,標(biāo)簽在其顯示區(qū)內(nèi)垂直居中對齊。默認(rèn)情況下,只顯示文本的標(biāo)簽是開始邊對齊;而只顯示圖像的標(biāo)簽則水平居中對齊。
JTextField?–一個輕量級組件,它允許編輯單行文本。
JPasswordField?– 允許我們輸入了一行字像輸入框,但隱藏星號(*) 或點(diǎn)創(chuàng)建密碼(密碼)
JButton?– JButton 類的實(shí)例。用于創(chuàng)建按鈕類似實(shí)例中的 "Login"。
在登錄代碼的成功后,將用戶名、密碼放入response,這樣頁面返回時瀏覽器會將cookie信息存入本地,在下次提交時,會將cookie信息一并提交,然后在登錄的開頭在request中取出。
cookie不安全,現(xiàn)在一般不用這個了,就算你加了密也不安全