By GokiSoft.com| 16:39 24/03/2021|
Java Advanced

[Share Code] Tìm hiểu về Localization - Quản lý sinh viên và kết nối cơ sở dữ liệu - Lập trình Jva nâng cao BT2228

#messages.properties


# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.

option_input = 1. Input student
option_display = 2. Display student list
choose = Choose:


#messages_vi_VN.properties


# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.

option_input = 1. NH\u1eacP TH\u00d4NG TIN SINH VI\u00caN
option_display = 2. HI\u1ec2N TH\u1eca TH\u00d4NG TIN SINH VI\u00caN
choose = CH\u1eccN:


#Student.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package aptech.java2.lesson07;

import java.util.List;

/**
 *
 * @author Diep.Tran
 */
public class Student {
    String name, email;

    public Student(String name, String email) {
        this.name = name;
        this.email = email;
    }

    public Student() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String toString() {
        return "Student{" + "name=" + name + ", email=" + email + '}';
    }
    
    public void input() {
        DataMgr dataMgr = DataMgr.getInstance();
        List<Student> list = dataMgr.getStudentList();
        
        List<Student> list2 = DataMgr.getInstance().getStudentList();
    }
}


#Main.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package aptech.java2.lesson07;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 *
 * @author Diep.Tran
 */
public class Main {
    public static void main(String[] args) {
        //Code chuc nang cho chuong trinh.
//        Student std = new Student();
//        std.input();

        showMenu();
    }
    
    static void showMenu() {
        //hard code -> fix cung du lieu text vao trong ctrinh.
//        Locale locale = Locale.US;
        Locale locale = Locale.JAPAN;
//        Locale locale = Locale.getDefault();
//        Locale locale = new Locale("vi", "VN");
        
        ResourceBundle bundle = ResourceBundle.getBundle("lang/messages", locale);
        
        System.out.println(bundle.getString("option_input"));
        System.out.println(bundle.getString("option_display"));
        System.out.println(bundle.getString("choose"));
    }
}


#DataMgr.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package aptech.java2.lesson07;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Diep.Tran
 */
public class DataMgr {
    List<Car> carList = new ArrayList<>();
    List<Student> studentList = new ArrayList<>();
    
    private static DataMgr instance = null;
    
    private DataMgr() {
    }
    
    public synchronized static DataMgr getInstance() {
        if(instance == null) {
            instance = new DataMgr();
        }
        return instance;
    }

    public List<Car> getCarList() {
        return carList;
    }

    public List<Student> getStudentList() {
        return studentList;
    }
}


#Car.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package aptech.java2.lesson07;

/**
 *
 * @author Diep.Tran
 */
public class Car {
    String name, color;

    public Car() {
    }

    public Car(String name, String color) {
        this.name = name;
        this.color = color;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Override
    public String toString() {
        return "Car{" + "name=" + name + ", color=" + color + '}';
    }
    
    
}


Tags:

Liên kết rút gọn:

https://gokisoft.com/2228

Bình luận