我在一个程序包中有三个类(LogIn
,EstimatedSalary
和Table
)。 Table
类包含一个GUI表,我想将其连接到LogIn
或EstimatedSalary
类中。是否比将GUI表放入我拥有的类之一更好?我尝试使用:
Table = null;
Table table=new table;
Table table = new Table();
在LogIn
类中为GUI表创建内部类
虽然并非一切都正常。我的计划是在用户成功访问工作时间后显示一个弹出表。
所有类都在工作,LogIn
和Estimated Salary
类已经连接。我的表格信息是这样的:
// Data to be displayed in the JTable
String[][] data = {
{ "Proj 1", "5", "CSE" },
{ "Proj 2", "4", "IT" }
};
// Column Names
String[] columnNames = { "Project Name", "Duration", "Department" };
public class LogIn extends EstimatedSalary {
public static void main(String[] args) {
int logginAttempts = 0;
String[] accessName = {"Lea", "Lino", "Lisa"};
String[] accessPassword = {"Smith", "Gray", "Collins"};
while (true) {
String userName = getUserNames();
String userPassword = getPassword();
boolean nameFound= checkUserInput(userName, accessName, userPassword, accessPassword);
if (nameFound) {
System.out.println("\n"+"Access Granted! Check your salary this month!"+"\n");
getPositionForMember();
**[//My first option to access the gui table here]**
System.exit(0);
}
else {
switch(logginAttempts) {
case 0: if(!nameFound){ System.out.println( "\n"+ "Please try again" + "\n");}
else{System.exit(0);}
break;
case 1: if(!nameFound){System.out.println("\n"+"Wrong password or Username. Please try again" + "\n");}
else{System.exit(0);}
break;
case 2: if(!nameFound){System.out.println("\n"+ "BLOCKED.");}
else{System.exit(0);}
break;
}
logginAttempts++;
if (logginAttempts >= 3) {
System.out.println("Maximum loggin attempts reached. Call Admin!");
System.exit(0);
}
}
}
}
预估工资类别
public static void getPositionForMember()
{
double position=getPosition();
if(position==1)
{
getSalaryForWD();
}
}
public static double getSalaryForWD()
{
Scanner input = new Scanner(System.in);
System.out.println("Please Enter your Estimated Hours this month:");
double hours = input.nextDouble();
double salary= 10.50 * hours;
System.out.println("Your estimated Salary this month: £" + salary);
System.out.println("Please wait a moment, the project for this year is loading...");
**[//Second option to access the gui table]**
return salary;
}