⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mynative.java

📁 java国际化编程
💻 JAVA
字号:
//:MyNative.java
/**
   Copyright (c) 2003 Dorian. All rights reserved 
   @(#)MyNative.java    2003-12-21
   @author Dorian
   @version 1.0.0
   visit http://www.Dorian.com/Java/
*/

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

/**
   这是一个将Java程序界面地方化的例子
   本例采用读取属性文件来达到目的
   @see java.util.Locale;
   @see java.util.ResourceBundle;
   @see java.util.MissingResourceException;
*/

public class MyNative{
	public static void main(String[] args){
		JFrame frame = new MyNativeFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setResizable(false);
		frame.setVisible(true);		// Pop the window up.
	}
}

class MyNativeFrame extends JFrame{
	public MyNativeFrame(){
		Locale locale = Locale.getDefault();//获取地区:默认
		//获取资源束。如未发现则会抛出MissingResourceException异常
		//"Properties.Dorian"为在Properties下以Dorian为文件名的默认属性文件
		ResourceBundle bundle = ResourceBundle.getBundle(
			"Properties.Dorian",locale);
		
		setTitle(bundle.getString("Title"));//通过getString()的返回值来设置Title
		setSize(WIDTH,HEIGHT);		// Set the window size.
		
		panel=new MyNativePanel();
		Container contentPane=getContentPane();
		contentPane.add(panel);
		
		//通过获取资源束中*.label的值对三个按钮设置其Label
		panel.setCmdRed(bundle.getString("red.label"));
		panel.setCmdBlue(bundle.getString("blue.label"));
		panel.setCmdGreen(bundle.getString("green.label"));
	}
	private MyNativePanel panel;
	private static final int WIDTH=400;
	private static final int HEIGHT=100;
}

class MyNativePanel extends JPanel{
	public MyNativePanel(){
		layout=new BorderLayout();
		setLayout(layout);
		
		txt=new JTextField(50);
		add(txt,layout.CENTER);
		
		cmdRed=new JButton();
		cmdBlue=new JButton();
		cmdGreen=new JButton();
		panel.add(cmdRed);
		panel.add(cmdBlue);
		panel.add(cmdGreen);
		add(panel,layout.SOUTH);
		
		cmdRed.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				String s = e.getActionCommand();
				
				txt.setBackground(Color.red);
				txt.setText(s);
			}
		});
		
		cmdBlue.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				String s = e.getActionCommand();
				
				txt.setBackground(Color.blue);
				txt.setText(s);
			}
		});
		
		cmdGreen.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				String s = e.getActionCommand();
				
				txt.setBackground(Color.green);
				txt.setText(s);
			}
		});
	}
	
	public void setCmdRed(String s){
		cmdRed.setText(s);
	}
	
	public void setCmdBlue(String s){
		cmdBlue.setText(s);
	}
	
	public void setCmdGreen(String s){
		cmdGreen.setText(s);
	}
	
	JPanel panel=new JPanel();
	BorderLayout layout;
	private JTextField txt;
	private JButton cmdRed,cmdBlue,cmdGreen;
}

//~

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -