每天有時(shí)間的話 , 會(huì)回答一兩個(gè)圖形界面的問(wèn)題, 但是分?jǐn)?shù)最好還是高點(diǎn)才有興趣.
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比武寧網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式武寧網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋武寧地區(qū)。費(fèi)用合理售后完善,十載實(shí)體公司更值得信賴。
具體代碼和詳細(xì)的注釋如下
員工類
public?class?Emp?{
private?int?num;//工號(hào)
private?String?name;//姓名
private?double?basicPay;//基本工資
private?double?meritPay;//績(jī)效工資
public?Emp(){//無(wú)參數(shù)構(gòu)造器
}
public?Emp(int?num,?String?name,?double?basicPay,?double?meritPay)?{//有參數(shù)構(gòu)造器
super();
this.num?=?num;
this.name?=?name;
this.basicPay?=?basicPay;
this.meritPay?=?meritPay;
}
//重寫Object的toString?方法
public?String?toString()?{
return?"工號(hào):"+num+"\t姓名:"+name+"\t基本工資:"+basicPay+"\t績(jī)效工資"+meritPay;
}
//下面是屬性的set和get
public?int?getNum()?{
return?num;
}
public?void?setNum(int?num)?{
this.num?=?num;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?double?getBasicPay()?{
return?basicPay;
}
public?void?setBasicPay(double?basicPay)?{
this.basicPay?=?basicPay;
}
public?double?getMeritPay()?{
return?meritPay;
}
public?void?setMeritPay(double?meritPay)?{
this.meritPay?=?meritPay;
}
}
輸入界面類
import?java.awt.*;
import?java.awt.event.*;
import?java.io.*;
import?javax.swing.*;
public?class?EmpFrome?extends?JFrame?implements?ActionListener?{
JTextField?jtfnum,?jtfname,?jtfbp,?jtfmp;
JButton?jbwtf;
public?EmpFrome()?{
JLabel?jl1?=?new?JLabel("工號(hào)");
jtfnum?=?new?JTextField(8);
add(jl1);
add(jtfnum);
JLabel?jl2?=?new?JLabel("姓名");
jtfname?=?new?JTextField(8);
add(jl2);
add(jtfname);
JLabel?jl3?=?new?JLabel("基本工資");
jtfbp?=?new?JTextField(8);
add(jl3);
add(jtfbp);
JLabel?jl4?=?new?JLabel("績(jī)效工資");
jtfmp?=?new?JTextField(8);
add(jl4);
add(jtfmp);
JLabel?jl5?=?new?JLabel();
jbwtf?=?new?JButton("寫入文件");
jbwtf.addActionListener(this);
add(jl5);
add(jbwtf);
setLayout(new?GridLayout(5,?2));
setTitle("員工信息錄入");
setSize(290,?230);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public?void?actionPerformed(ActionEvent?e)?{
String?cmd?=?e.getActionCommand();
if?(cmd.equals("寫入文件"))?{
try{
//獲取數(shù)據(jù)
int?num?=?Integer.parseInt(jtfnum.getText().trim());
String?name?=?jtfname.getText().trim();
double?bp?=?Double.parseDouble(jtfbp.getText().trim());
double?mp?=?Double.parseDouble(jtfmp.getText().trim());
Emp?emp?=?new?Emp(num,?name,?bp,?mp);
writeToFile(emp);
JOptionPane.showMessageDialog(this,?"錄入成功");//提示成功
//清空文本框
jtfnum.setText("");
jtfname.setText("");
jtfbp.setText("");
jtfmp.setText("");
}catch(Exception?ex){
//當(dāng)輸入不符合規(guī)范時(shí)?,??提示錯(cuò)誤
JOptionPane.showMessageDialog(this,?"請(qǐng)輸入正確的數(shù)據(jù):\n工號(hào)整型,工資浮點(diǎn)型","錄入錯(cuò)誤",JOptionPane.ERROR_MESSAGE);
}
}
}
//定義的文件路徑?
final?static?String?FILE_PATH?=?"employee.dat";
public?void?writeToFile(Emp?emp)??{//IO操作,追加寫入
BufferedWriter?bw?=?null;
try?{
bw?=?new?BufferedWriter(new?FileWriter(new?File(FILE_PATH),?true));//為true表示追加
bw.write(emp.toString());//寫入員工信息
bw.newLine();//換行
}?catch?(IOException?e)?{
e.printStackTrace();
}finally{
if(bw!=null){
try?{
bw.close();
}?catch?(IOException?e)?{
e.printStackTrace();
}
}
}
}
}
測(cè)試類
public?class?EmpTest?{
public?static?void?main(String[]?args)?{
new?EmpFrome();
}
}
測(cè)試效果
兄弟可以聯(lián)系 hi留言也行
我這里保留了,從學(xué)習(xí)java第一天起到現(xiàn)在 學(xué)習(xí)練習(xí)代碼,
基礎(chǔ)部分注釋很詳細(xì)。
//每一位相加求和
public class Demo
{
public static void main(String[] args)
{
int i = 45678;
int sum = 0;
int c = 0;
for(int j = 4; j = 0; j--)
{
int b = (int) Math.pow(10, j);
c = i / b;
System.out.println(c);
sum += c;
System.out.println("sum=" + sum);
i %= b;
}
System.out.println(sum);
}
}
public class ZY1030
{
public static void main(String[] asgs)
{
zy1();
zy2();
zy3();
zy4();
zy5();
zy6();
zy7();
yanghuisanjiao();
}
public static void yanghuisanjiao()
{
int[][] pas = new int[6][];
for(int i = 0; i pas.length; i++)
{
pas[i] = new int[i + 1];
pas[i][0] = 1;
pas[i][i] = 1;
for(int j = 0; j pas[i].length - 1; j++)
{
if(j = 1 i 1)
pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j];
}
}
for(int i = 0; i pas.length; i++)
{
for(int j = 0; j pas[i].length; j++)
{
System.out.print(pas[i][j]);
System.out.println();
}
}
System.out.println();
}
private static void zy1()
{
System.out.println("???1");
/*
*
**
***
****
*****
******
*******
*/
for(int r = 0; r 7; r++)
{
for(int j = 0; j r + 1; j++)
{
System.out.print("*");
}
System.out.println();
}
}
private static void zy2()
{
System.out.println("\n???2");
/*
*
***
*****
*******
*********
*/
for(int r = 0; r = 5; r++)
{
for(int j = 0; j 11 - r; j++)
{
System.out.print(" ");
}
for(int j = 0; j r * 2 + 1; j++)
{
System.out.print("*");
}
System.out.println();
}
}
private static void zy3()
{
System.out.println("\n???3");
/*
*
* *
* * *
* * * *
* * * * *
*/
for(int r = 0; r = 5; r++)
{
for(int j = 0; j 10 - r; j++)
{
System.out.print(" ");
}
for(int j = 0; j r; j++)
{
System.out.print("* ");
}
System.out.println();
}
}
private static void zy4()
{
System.out.println("\n???4");
/*
***********
***********
***********
***********
***********
*/
for(int r = 0; r = 5; r++)
{
for(int j = 0; j 7 - r; j++)
{
System.out.print(" ");
}
for(int j = 0; j 10; j++)
{
System.out.print("*");
}
System.out.println();
}
}
private static void zy5()
{
System.out.println("\n???5");
/*
1X1=1
1X2=2 2X2=4
1X3=3 2X3=6 3X3=9
....
*/
for(int r = 1; r = 9; r++)
{
for(int j = 1; j = r; j++)
{
int iValue = j * r; //?????
String str = j + "X" + r + "=" + iValue + " ";
System.out.print(str);
//System.out.print(" J:" + j);
}
System.out.println();
//System.out.println("R:" + r);
}
}
private static void zy6()
{
System.out.println("\n???6");
/*
??????(????) ????1??????????????????
3 5 7 11 13 17 19 23 ....
int n = 4;
boolean t = true; // assume is SU_SHU
for(int i=2; in; i++)
{
if(n%i==0)
{
t = false;
break;
}
}
System.out.println(t);
*/
for(int i = 2; i = 100; i++)
{
// if(i % 2 ==0 || i % 3 == 0 )
// {
// continue;
// }
// System.out.print(i + " ");
boolean bTrue = true;
for(int j = 2; j i; j++)
{
if(i % j == 0)
{
bTrue = false;
break;
}
}
if(bTrue)
{
System.out.println(i);
}
}
System.out.println();
}
private static void zy7()
{
System.out.println("\n???7");
/*
int n = 23623;
int x = n % 100000 / 10000;
System.out.println(x);
x = n % 10000 / 1000;
System.out.println(x);
x = n % 1000 / 100;
System.out.println(x);
*/
}
}
我用了半個(gè)小時(shí) 幫你寫了一個(gè)簡(jiǎn)單的驗(yàn)證用戶名和密碼登陸問(wèn)題 別辜負(fù)我的好意 下面是代碼!(建好包和類 代碼粘過(guò)去就能用)
實(shí)體類 包entity
-------------------------------------------------------------
package entity;
/**
* 用戶實(shí)體類
* @author new
*
*/
public class Users {
private String name;//用戶名
private String pass;//用戶密碼
/**
* 空的構(gòu)造函數(shù) 用戶實(shí)力化 此類對(duì)象
*/
public Users(){
}
/**
* 構(gòu)造函數(shù) 接收用戶名和密碼
* @param name
* @param pass
*/
public Users(String name, String pass) {
this.name = name;
this.pass = pass;
}
/**
* 下面set和get方法就不用解釋了吧
* @return
*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
}
數(shù)據(jù)庫(kù)類 包dao(我是模擬一下數(shù)據(jù)庫(kù) 沒(méi)有用到數(shù)據(jù)庫(kù))
--------------------------------------------------------------
package dao;
import java.util.*;
import entity.Users;//導(dǎo)入實(shí)體類
/**
* 模擬數(shù)據(jù)庫(kù) 用戶DAO
* @author new
*
*/
public class UsersDAO {
private static Users users=new Users();
static
{
users.setName("tom");
users.setPass("jerry");
}
/**
* 根據(jù)姓名查找這個(gè)用戶 (模擬一下數(shù)據(jù)庫(kù))
* @param name
* @return
*/
public Users findUserByName(String name)
{
if(name.equals(this.users.getName()))
{
return this.users;
}
return null;
}
}
業(yè)務(wù)類 包service (驗(yàn)證用戶名和密碼)
------------------------------------------------------------
package service;
import dao.UsersDAO;
import entity.Users;
/**
* 驗(yàn)證密碼 業(yè)務(wù)類
* @author new
*
*/
public class validatePass {
//實(shí)力化DAO對(duì)象
private UsersDAO us=new UsersDAO();
/**
* 驗(yàn)證輸入的密碼是否正確
* @param name
* @param pass
* @return
*/
public Users validate(String name,String pass)
{
Users user=null;
user=us.findUserByName(name);
//如果不為空 說(shuō)明查到了
if(user!=null)
{
//用查詢出來(lái)對(duì)象的密碼和傳過(guò)來(lái)的密碼比較
if(user.getPass().equals(pass))
{
return user;
}
}
return null;
}
}
最后是測(cè)試test類 包test
----------------------------------------------------------
package test;
import entity.Users;
import service.validatePass;
/**
* 測(cè)試類
* @author new
*
*/
public class test {
/**
* main方法 用于測(cè)試
* @param args
*/
public static void main(String[] args)
{
//實(shí)例化業(yè)務(wù)類對(duì)象
validatePass v=new validatePass();
//用戶名和密碼
String name="tom";
String pass="jerry";
//開始驗(yàn)證
Users user=v.validate(name, pass);
if(user==null)
{
System.out.println("你輸入的用戶名或密碼錯(cuò)誤!");
}else
{
System.out.println("你已經(jīng)通過(guò)驗(yàn)證,成功登陸!");
}
}
}
package com.io2.homework;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/*壓縮文件夾*/
public class MyMultipleFileZip
{
private String currentZipFilePath = "F:/MyZip.zip";
private String sourceFilePath;
private ZipOutputStream zos;
private FileInputStream fis;
public MyMultipleFileZip(String sourceFilePath)
{
try
{
this.sourceFilePath = sourceFilePath;
zos = new ZipOutputStream(new FileOutputStream(currentZipFilePath));
//設(shè)定文件壓縮級(jí)別
zos.setLevel(9);
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
// 在當(dāng)前條目中寫入具體內(nèi)容
public void writeToEntryZip(String filePath)
{
try
{
fis = new FileInputStream(filePath);
} catch (FileNotFoundException e1)
{
e1.printStackTrace();
}
byte[] buff = new byte[1024];
int len = 0;
try
{
while ((len = fis.read(buff)) != -1)
{
zos.write(buff, 0, len);
}
} catch (IOException e)
{
e.printStackTrace();
}finally
{
if (fis != null)
try
{
fis.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
// 添加文件條目
public void addFileEntryZip(String fileName)
{
try
{
zos.putNextEntry(new ZipEntry(fileName));
} catch (IOException e)
{
e.printStackTrace();
}
}
public void addDirectoryEntryZip(String directoryName)
{
try
{
zos.putNextEntry(new ZipEntry(directoryName + "/"));
} catch (IOException e)
{
e.printStackTrace();
}
}
// 遍歷文件夾
public void listMyDirectory(String filePath)
{
File f = new File(filePath);
File[] files = f.listFiles();
if(files!=null)
{
for (File currentFile : files)
{
// 設(shè)置條目名稱(此步驟非常關(guān)鍵)
String entryName= currentFile.getAbsolutePath().split(":")[1].substring(1);
// 獲取文件物理路徑
String absolutePath = currentFile.getAbsolutePath();
if (currentFile.isDirectory())
{
addDirectoryEntryZip(entryName);
//進(jìn)行遞歸調(diào)用
listMyDirectory(absolutePath);
}
else
{
addFileEntryZip(entryName);
writeToEntryZip(absolutePath);
}
}
}
}
// 主要流程
public void mainWorkFlow()
{
listMyDirectory(this.sourceFilePath);
if(zos!=null)
try
{
zos.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new MyMultipleFileZip("F:/fountainDirectory").mainWorkFlow();
}
}
第一題
import java.util.Random;
import java.util.Scanner;
public class Guess{
public static void main(String[] args) {
int rightNum = new Random().nextInt(100) + 1;
Scanner scanner = new Scanner(System.in);
int input = 0;
do{
System.out.print("清猜數(shù)字(1-100)!");
input = scanner.nextInt();
if(input rightNum){
System.out.println("猜大了!");
}
else if(input rightNum){
System.out.println("猜小了!");
}
}while(input != rightNum);
System.out.println("猜對(duì)了" + rightNum);
}
}
第二題
import java.util.* ;
public class A{
public static void main(String args[]){
int i,j,k,temp;
int a[][]=new int[2][3];
a[0][0]=(int)(100*Math.random());
a[0][1]=(int)(100*Math.random());
a[0][2]=(int)(100*Math.random());
a[1][0]=(int)(100*Math.random());
a[1][1]=(int)(100*Math.random());
a[1][2]=(int)(100*Math.random());
for(j=0;j3;j++)
System.out.println("a[0]["+j+"]="+a[0][j]);
System.out.println(" ");
for(j=0;j3;j++)
System.out.println("a[1]["+j+"]="+a[1][j]);
System.out.println(" ");
for(i=0;i2;i++){
for(j=0;j2;j++){
for(k=j;k2;k++){
if(a[i][j]a[i][k+1]){
temp=a[i][j];
a[i][j]=a[i][k+1];
a[i][k+1]=temp;
}
}
}
}
System.out.println("第一行按從小到大排列:");
for(j=0;j3;j++){
System.out.println("a[0]["+j+"]="+a[0][j]);
}
System.out.println("第二行按從小到大排列:");
for(j=0;j3;j++)
System.out.println("a[1]["+j+"]=" +a[1][j]);
}
}
春春??還不快采納嘛