无法理解问题要..Java [英] Can't understand what the question want..Java

查看:58
本文介绍了无法理解问题要..Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我分配了一个程序来构建一个类似下面的问题的程序..我编写了一些具有登录名和密码的代码..它也从网站上获得了..但是我的朋友告诉我我不满足这个问题想要..有人可以向我解释这个问题想要什么吗?
我是JAVA环境中的新手.谢谢

Q1.许多电子商务网站和Intranet都需要登录名和密码才能访问网站中的数据.编写一个applet,通过JoptionPane包的INPUT DIALOG询问用户ID和密码.用户输入登录名和密码后,小程序将搜索一组ID和密码以进行验证(每个数组由5个值组成).然后,小程序将显示一条适当的消息.编写代码以创建两个数组,一个数组用于ID,一个数组用于相应的密码.您将编写循环以遍历数组,搜索有效的ID和密码.

Q2.基于问题1,您需要通过文本字段和passwordField接受用户输入,登录名和密码.用户按下登录名和密码后,小程序将搜索一组ID和密码以进行验证.然后,小程序将显示一条适当的消息.编写代码以创建两个数组,一个数组用于ID,一个数组用于相应的密码.您将编写循环以遍历数组,搜索有效的ID和密码.

Q3.根据问题2,输入,登录名和密码均来自文本字段.密码未显示在小程序上.字符"*"用于显示,而不是字母数字字符. setEchoChar()方法用于在TextField中显示"*"(请勿使用passwordField).用户按下登录按钮后,小程序将搜索一组ID和密码以进行验证.然后,该小程序将显示一条适当的消息.


编码

导入javax.swing.*;
导入java.awt.*;
导入java.awt.event.*;
 
类Login扩展JFrame实现ActionListener
{
 JButton提交;
 JPanel面板;
 JLabel label1,label2;
 最后的JTextField text1,text2;
  登录()
  {
  label1 =新的JLabel();
  label1.setText(" );
  text1 = new JTextField( 15 );

  label2 =新的JLabel();
  label2.setText(" );
  text2 = new JPasswordField( 15 );
 
  SUBMIT = new JButton(" );
  
  panel = new JPanel(new GridLayout( 3  1 ));
  添加(label1);
  添加(text1);
  添加(label2);
  添加(text2);
  添加(提交);
  添加(面板,BorderLayout.CENTER);
  SUBMIT.addActionListener(this);
  setTitle(" );
  }
 公共 void actionPerformed(ActionEvent ae)
  {
  字符串value1 = text1.getText();
  字符串value2 = text2.getText();
  如果(value1.equals(" )& value2.equals(" )){
  NextPage page = new NextPage();
  page.setVisible(true);
  JLabel标签=新的JLabel("  + value1);
  page.getContentPane().添加(标签);
  }
  其他 {
  System.out.println(" );
  JOptionPane.showMessageDialog(this," " ,JOptionPane.ERROR_MESSAGE);
  }
}
}
 类LoginDemo
{
  公共静态void main(String arg [])
  {
  尝试
  {
  Login frame = new Login();
  frame.setSize( 300  100 );
  frame.setVisible(true);
  }
  catch(异常e)
  {JOptionPane.showMessageDialog(,e.getMessage());}
  }
} 




导入javax.swing.*;
导入java.awt.*;

 class  NextPage扩展了JFrame
{
  下一页()
 {
 setDefaultCloseOperation(javax.swing.
  WindowConstants.DISPOSE_ON_CLOSE);
 setTitle(" );
 setSize( 400  200 );
  }
 } 

解决方案

OP之类的声音是由他自己解决的,因此将其发布到未答复列表之外.


I got an assignment to build one program like the question below .. I made a bit of code that has a login and password ..Its also get from the website.. but my friend told me do not meet what the question wants .. is there anyone who can explain to me what the question wants?
I am new in JAVA environment..Thanz

Q1.Many e-commerce websites and intranets require a login and password in order to access data from the site. Write an applet that will ask the user for ID and password through INPUT DIALOG of JoptionPane package. Once the user entered the login and password, the applet will search through an array of Ids and passwords for verification (each array consist of 5 values). The applet then will display an appropriate message. Write the code to create two arrays, one for IDs and one for the corresponding passwords. You will write a loop to progress through the array, searching for a valid ID and password.

Q2.Based on question 1, you are required to accept the user input , login and password through text field and passwordField. Once the user pressed the login and password, the applet will search through an array of Ids and passwords for verification. The applet then will display an appropriate message. Write the code to create two arrays, one for IDs and one for the corresponding passwords. You will write a loop to progress through the array, searching for a valid ID and password.

Q3.Based on question 2, both input, login and password will be from text field. Thepassword is not displayed on the applet. The character ‘*’ is used to displayed instead of the alphanumeric characters. The method setEchoChar() is used to display ‘*’ in the TextField (DO not use passwordField). Once the user pressed the login button, the applet will search through an array of IDs and passwords for verification. The applet then will display an appropriate message.


Coding

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
class Login extends JFrame implements ActionListener
{
 JButton SUBMIT;
 JPanel panel;
 JLabel label1,label2;
 final JTextField  text1,text2;
  Login()
  {
  label1 = new JLabel();
  label1.setText("Username:");
  text1 = new JTextField(15);

  label2 = new JLabel();
  label2.setText("Password:");
  text2 = new JPasswordField(15);
 
  SUBMIT=new JButton("SUBMIT");
  
  panel=new JPanel(new GridLayout(3,1));
  panel.add(label1);
  panel.add(text1);
  panel.add(label2);
  panel.add(text2);
  panel.add(SUBMIT);
  add(panel,BorderLayout.CENTER);
  SUBMIT.addActionListener(this);
  setTitle("LOGIN FORM");
  }
 public void actionPerformed(ActionEvent ae)
  {
  String value1=text1.getText();
  String value2=text2.getText();
  if (value1.equals("Bacteria") && value2.equals("Bacteria")) {
  NextPage page=new NextPage();
  page.setVisible(true);
  JLabel label = new JLabel("Welcome:"+value1);
  page.getContentPane().add(label);
  }
  else{
  System.out.println("enter the valid username and password");
  JOptionPane.showMessageDialog(this,"Incorrect login or password",
  "Error",JOptionPane.ERROR_MESSAGE);
  }
}
}
 class LoginDemo
{
  public static void main(String arg[])
  {
  try
  {
  Login frame=new Login();
  frame.setSize(300,100);
  frame.setVisible(true);
  }
  catch(Exception e)
  {JOptionPane.showMessageDialog(null, e.getMessage());}
  }
}




import javax.swing.*;
import java.awt.*;

class NextPage extends JFrame
{
  NextPage()
 {
 setDefaultCloseOperation(javax.swing.
  WindowConstants.DISPOSE_ON_CLOSE);
 setTitle("Welcome");
 setSize(400, 200);
  }
 }

解决方案

Sounds like OP resolved it by himself so posting this to put it out of unanswered list.


这篇关于无法理解问题要..Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆