求java程序解答

求java程序解答,第1张

第一个

import javaawtPoint;

import javaawtToolkit;

import javaawteventMouseEvent;

import javaawteventMouseListener;

import javaxswingJButton;

import javaxswingJFrame;

import javaxswingJLabel;

import javaxswingJOptionPane;

import javaxswingJPasswordField;

import javaxswingJTextField;

/

一个简单的Swing窗口,输入内容单击“确定”按钮后,在文本域中显示输入的内容。

单击“取消”按钮,清空页面内容。

@author yzg

/

public class Test extends JFrame {

private static final long serialVersionUID = 1L;

private JLabel nameLabel;

private JLabel pwdLabel;

private JTextField name;

private JTextField pwd;

public Test(String title) {

super(title);

thisgetContentPane()setLayout(null);

// 下面两行是取得屏幕的高度和宽度

double lx = ToolkitgetDefaultToolkit()getScreenSize()getWidth();

double ly = ToolkitgetDefaultToolkit()getScreenSize()getHeight();

thissetLocation(new Point((int) (lx / 2) - 150, (int) (ly / 2) - 200));// 设定窗口出现位置

thissetSize(340, 440);// 设定窗口大小

}

public void showWin() {

thissetDefaultCloseOperation(EXIT_ON_CLOSE);

// 姓名

nameLabel = new JLabel("姓名 :");

nameLabelsetBounds(30, 10, 50, 25);

name = new JTextField();

namesetBounds(80, 10, 120, 20);

pwdLabel = new JLabel("密码 :");

pwdLabelsetBounds(30, 40, 50, 55);

pwd = new JPasswordField();

pwdsetBounds(80, 40, 120, 50);

// 确定按钮

JButton ok = new JButton("确定");

oksetBounds(50, 190, 60, 25);

okaddMouseListener(new MouseListener() {

public void mouseClicked(MouseEvent e) {

if ("admin"equals(namegetText())&&"123456"equals(pwdgetText())) {

JOptionPaneshowMessageDialog(getContentPane(), "登录成功");

}else {

JOptionPaneshowMessageDialog(getContentPane(), "登录不成功");

}

}

public void mouseEntered(MouseEvent e) {

}

public void mouseExited(MouseEvent e) {

}

public void mousePressed(MouseEvent e) {

}

public void mouseReleased(MouseEvent e) {

}

});

// 取消按钮

JButton cancel = new JButton("取消");

cancelsetBounds(120, 190, 60, 25);

canceladdMouseListener(new MouseListener() {

public void mouseClicked(MouseEvent e) {

}

public void mouseEntered(MouseEvent e) {

}

public void mouseExited(MouseEvent e) {

}

public void mousePressed(MouseEvent e) {

}

public void mouseReleased(MouseEvent e) {

}

});

thisgetContentPane()add(nameLabel);

thisgetContentPane()add(pwdLabel);

thisgetContentPane()add(name);

thisgetContentPane()add(pwd);

thisgetContentPane()add(ok);

thisgetContentPane()add(cancel);

// thispack();

thissetVisible(true);

}

/

@param args

/

public static void main(String[] args) {

Test reg = new Test("test");

regshowWin();

}

}

第二个

import javaawtPoint;

import javaawtToolkit;

import javaawteventMouseEvent;

import javaawteventMouseListener;

import javaxswingJButton;

import javaxswingJFrame;

import javaxswingJOptionPane;

/

一个简单的Swing窗口,输入内容单击“确定”按钮后,在文本域中显示输入的内容。

单击“取消”按钮,清空页面内容。

@author yzg

/

public class Test extends JFrame {

private static int count=0;

private static final long serialVersionUID = 1L;

public Test(String title) {

super(title);

thisgetContentPane()setLayout(null);

// 下面两行是取得屏幕的高度和宽度

double lx = ToolkitgetDefaultToolkit()getScreenSize()getWidth();

double ly = ToolkitgetDefaultToolkit()getScreenSize()getHeight();

thissetLocation(new Point((int) (lx / 2) - 150, (int) (ly / 2) - 200));// 设定窗口出现位置

thissetSize(340, 440);// 设定窗口大小

}

public void showWin() {

// 确定按钮

JButton ok = new JButton("确定");

oksetBounds(50, 190, 60, 25);

okaddMouseListener(new MouseListener() {

public void mouseClicked(MouseEvent e) {

count++;

JOptionPaneshowMessageDialog(getContentPane(),count);

}

public void mouseEntered(MouseEvent e) {

}

public void mouseExited(MouseEvent e) {

}

public void mousePressed(MouseEvent e) {

}

public void mouseReleased(MouseEvent e) {

}

});

thisgetContentPane()add(ok);

// thispack();

thissetVisible(true);

}

/

@param args

/

public static void main(String[] args) {

Test reg = new Test("test");

regshowWin();

}

}

import javatextNumberFormat;

import javautilArrayList;

public class TestBanking {

public static void main(String[] args) {

NumberFormat currency_format=NumberFormatgetCurrencyInstance();

Bank bank=new Bank();

Customer customer;

bankaddCustomer("Jane","Simms");

customer=bankgetCustomer(0);

customeraddAccount(new SavingsAccount(50000,005));

customeraddAccount(new CheckingAccount(20000,40000));

bankaddCustomer("Owen", "Bryant");

customer=bankgetCustomer(1);

customeraddAccount(new CheckingAccount(2000));

bankaddCustomer("Tim", "Soley");

customer=bankgetCustomer(2);

customeraddAccount(new SavingsAccount(150000, 005));

customeraddAccount(new CheckingAccount(20000));

bankaddCustomer("Maria", "Soley");

customer=bankgetCustomer(3);

customeraddAccount(bankgetCustomer(2)getAccount(1));

customeraddAccount(new SavingsAccount(15000, 005));

Systemoutprintln("\t\t\tCUSTOMERS REPORT");

Systemoutprintln("\t\t\t==============");

for(int cust_idx=0;cust_idx<bankgetNumOfCustomers();cust_idx++){

customer=bankgetCustomer(cust_idx);

Systemoutprintln();

Systemoutprintln("Customer: "+customergetLastName()+","+customergetFirstName());

for(int acct_idx=0;acct_idx<customergetNumOfAccounts();acct_idx++){

Account account=customergetAccount(acct_idx);

String account_type="";

if(account instanceof SavingsAccount){

account_type="Savings Account";

}

else if(account instanceof CheckingAccount){

account_type="Checking Account";

}

Systemoutprintln(account_type+": current balance is �"+ accountgetA());

}

}

}

}

/

银行对象

/

class Bank{

Customer customer;

ArrayList<Customer> customers;

int i;

int numOfCustomers=0;

public Bank(){

customers=new ArrayList<Customer>();

}

public Customer getCustomer(int i) {

customer=customersget(i);

return customer;

}

public int getNumOfCustomers() {

return numOfCustomers;

}

public void setCustomer(int i) {

}

public void addCustomer(String string, String string2) {

numOfCustomers++;

customersadd(new Customer(string, string2));

}

}

/

顾客对象

/

class Customer{

Account account;

ArrayList<Account> accounts;

String firstName;

String lastName;

int numOfAccounts=0;

Customer(String firstName,String lastName){

accounts=new ArrayList<Account>();

thisfirstName=firstName;

thislastName=lastName;

}

public int getNumOfAccounts() {

// TODO Auto-generated method stub

return numOfAccounts;

}

public Account getAccount(int id) {

account=accountsget(id);

return account;

}

public void setAccount(Account account) {

thisaccount = account;

}

public String getFirstName() {

return firstName;

}

public void setFirstName(String firstName) {

thisfirstName = firstName;

}

public String getLastName() {

return lastName;

}

public void setLastName(String lastName) {

thislastName = lastName;

}

public void addAccount(Account account) {

numOfAccounts++;

accountsadd(account);

}

}

class SavingsAccount extends Account{ //储蓄账户

public SavingsAccount(double a, double b) {

super(a,b);

}

public SavingsAccount(double c){

super(c);

}

}

class CheckingAccount extends Account{

public CheckingAccount(double c) {

super(c);

} //支票账户

public CheckingAccount(double a,double b){

super(a,b);

}

}

class Account{

double a;

double b;

public double getA() {

return a;

}

public void setA(double a) {

thisa = a;

}

public double getB() {

return b;

}

public void setB(double b) {

thisb = b;

}

public Account(double f, double g){

a= f;

b= g;

}

public Account(double c){

a=c;

}

}

你可以试一下,前两个要求都有满足,后面那个随意使用currency_format格式化程序来生成一个字符串“货币”的balance不是很明白意思,有问题再问吧

/

判断是存在指定名称的进程存在

@param taskName 进程名称

@return 如果存在,返回true;如果不存在,返回false。

/

private boolean existProcess(String taskName){

try {

Process process = RuntimegetRuntime()exec("cmd /c tasklist");

ByteArrayOutputStream baos = new ByteArrayOutputStream();

InputStream stream = processgetInputStream();

byte[] b = new byte[256];

while (streamread(b) > 0) {

baoswrite(b);

String string = baostoString();

if(stringindexOf(taskName) >= 0){

return true;

}

}

} catch (IOException e) {

eprintStackTrace();

}

return false;

}

/

结束指定名称的进程

@param taskName 进程名称

/

private void killProcess(String taskName){

try {

Process process = RuntimegetRuntime()exec("cmd /c taskkill /f /im "+taskName+" /t");

} catch (IOException e) {

eprintStackTrace();

}

private void writeLogs(String taskName){

Process process = RuntimegetRuntime()exec("cmd /c "+"软件exe位置");

OutputStream os = processgetOutputStream(); //得到标准输出流

//根据这个输出流来写你的日志吧

}

}

以上就是关于求java程序解答全部的内容,包括:求java程序解答、JAVA编程程序问题、能不能用java编写一个计算机软件监控程序,监控某一个软件的输入输出,并将其存入指定的文件等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/10213271.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-06
下一篇2023-05-06

发表评论

登录后才能评论

评论列表(0条)

    保存