日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java启动密码,java - 用户验证密码后如何启动java applet程序? - SO中文参考 - www.soinside.com...

發(fā)布時間:2023/12/20 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java启动密码,java - 用户验证密码后如何启动java applet程序? - SO中文参考 - www.soinside.com... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我正在嘗試連接兩個簡單的java程序,一個密碼登錄程序,然后打開第二個程序(一個非常簡單的PrintWriter程序)。

我是一個大型菜鳥,所以嘗試將二級程序添加到密碼程序中。顯然這沒用。我看到很多關于創(chuàng)建密碼程序的條目,以及一些關于使用.exec來運行外部應用程序的條目。我想我要做的是嵌入一個在用戶登錄后運行的程序。

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

public class PasswordApplet extends Applet implements ActionListener

{

//Declaring variables

String id, password;

String[] validID = { "id1", "id2"};

String[] validPassword = { "password1", "password2"};

boolean success;

//Create components for applet

Label headerLabel = new Label("Please type your ID and Password");

Label idLabel = new Label("ID: ");

TextField idField = new TextField(8);

Label passwordLabel = new Label("Password: ");

TextField passwordField = new TextField(8);

Button loginButton = new Button("Login");

public void init()

{

//set color, layout, and add components

setBackground(Color.orange);

setLayout(new FlowLayout(FlowLayout.LEFT, 50, 30));

add(headerLabel);

add(idLabel);

add(idField);

idField.requestFocus();

add(passwordLabel);

add(passwordField);

passwordField.setEchoChar('*');

add(loginButton);

loginButton.addActionListener(this);

}

public void actionPerformed(ActionEvent e)

{

success = false;

//Sequential search

int i = 0;

while ( i

{

if(idField.getText().compareTo(validID[i]) == 0)

{

if (passwordField.getText().compareTo(validPassword[i]) == 0)

{

success = true;

}

}

i = i + 1;

}

if (success == true)

{

headerLabel.setText("Login successful");

}

else

{

headerLabel.setText("Unsuccessful. Try Again");

idField.setText(" ");

passwordField.setText(" ");

idField.requestFocus();

}

repaint();

}

}

這是第二個PrintWriter程序:

import java.io.*;

public class Philosophers

{

public static void main(String[] args) throws IOException

{

//Declare a PrintWriter variable named myFile and open a file

named philosophers.rtf.

PrintWriter myFile = new PrintWriter("philosophers.rtf");

//Write the names of 3 philosophers to the file

myFile.println("John Locke");

myFile.println("David Hume");

myFile.println("Edmund Burke");

//Close the file

myFile.close();

}

}

總結

以上是生活随笔為你收集整理的java启动密码,java - 用户验证密码后如何启动java applet程序? - SO中文参考 - www.soinside.com...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。