Demo

package com.huawei.crs.dataswitch.ui;



import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.Border;

public class DataSwitchUI
{
	public static void main(String[] args)
	{

    	//获取屏幕尺寸
    	Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    	
    	try
		{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e1)
		{
			e1.printStackTrace();
		} catch (InstantiationException e1)
		{
			e1.printStackTrace();
		} catch (IllegalAccessException e1)
		{
			e1.printStackTrace();
		} catch (UnsupportedLookAndFeelException e1)
		{
			e1.printStackTrace();
		}
		
    	final JFrame jFrame = new JFrame("数据切换SQL脚本生成工具");
		Image image = null;
		
		try
		{
			image = ImageIO.read(new FileInputStream("img/logo.jpg"));
		} 
		catch (FileNotFoundException e)
		{
			JOptionPane.showMessageDialog(jFrame,"图片Logo没有找到 !","警告信息",JOptionPane.WARNING_MESSAGE);
			//System.exit(0);
		} 
		catch (IOException e)
		{
			JOptionPane.showMessageDialog(jFrame,"读取文件异常 !","警告信息",JOptionPane.WARNING_MESSAGE);
			//System.exit(0);
		}  

        jFrame.setIconImage(image);
    	Container container = jFrame.getContentPane();
    	container.setLayout(null);

		final JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 10, 770, 180);
		scrollPane.setWheelScrollingEnabled(true);
		scrollPane.setBorder(BorderFactory.createTitledBorder("信息栏"));
		container.add(scrollPane);
    	
    	
		final JTextArea resultTextArea = new JTextArea();
		
		Color color = new Color( 255, 255, 255);
		Color selectedColor = new Color( 0, 255, 0);
		
		Border border = BorderFactory.createLineBorder(Color.black);
		//border = BorderFactory.createLoweredBevelBorder();
		//border = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
		//border = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
		//border = BorderFactory.createRaisedBevelBorder();
		
		resultTextArea.setBorder(border);
		resultTextArea.setBackground(color);
		resultTextArea.setSelectedTextColor(selectedColor);
		resultTextArea.setText(
				"\n\t数据切换SQL脚本生成工具说明: " +
				"\n\t\t\t 待补充");
		
		resultTextArea.setEditable(false);
		scrollPane.setViewportView(resultTextArea);
		
		
		JPanel comparePane = new JPanel();
		comparePane.setLayout(null);
		comparePane.setBounds(10, 200, 770, 120);
		comparePane.setBorder(BorderFactory.createTitledBorder("生成SQL脚本文件"));
		container.add(comparePane);
		
		
		JLabel expectLabel = new JLabel("模  块:");
		expectLabel.setBounds(60, 40, 80, 26);
		comparePane.add(expectLabel);
		
		final JTextField expectTextField = new JTextField();
		expectTextField.setBounds(120, 40, 220, 26);
		comparePane.add(expectTextField);

		
		expectTextField.addKeyListener(new KeyAdapter(){

			@Override
			public void keyReleased(KeyEvent e) {
				StringBuffer sb = new StringBuffer();
				String content = expectTextField.getText();
				System.out.println(content);
				
				int len = 5;

				for(int i = 0; len * i <= content.length(); i++)
				{
					sb.append(content.substring(i, len * i));
					sb.append("\n");
				}
				
				System.out.println(sb.toString());
				
//				resultTextArea.setText(sb.toString());
			}
		});
		
		
		JLabel actualLabel = new JLabel("文  件:");
		actualLabel.setBounds(390, 40, 80, 26);
		comparePane.add(actualLabel);
		
		final JTextField actualTextField = new JTextField();
		actualTextField.setBounds(450, 40, 200, 26);
		comparePane.add(actualTextField);
		
    	
		JButton actualButton = new JButton("...");
		actualButton.setBounds(650, 40, 20, 26);
		comparePane.add(actualButton);
		actualButton.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				JFileChooser jFileChooser = new JFileChooser();
				 int returnVal = jFileChooser.showSaveDialog(jFrame); 
	             if (returnVal == JFileChooser.APPROVE_OPTION) 
	             { 
	                 File file = jFileChooser.getSelectedFile();               
	                 actualTextField.setText(file.getAbsolutePath());
	             }
			}
		});
		
		JButton compareButton = new JButton("生成脚本");
		compareButton.setBounds(590, 80, 80, 26);
		comparePane.add(compareButton);
		compareButton.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				String expaceFile = expectTextField.getText();
				String actualFile = actualTextField.getText();
				if(null == expaceFile || "".equals(expaceFile))
				{
					JOptionPane.showMessageDialog(jFrame,"预期文件不能为空!","警告信息",JOptionPane.WARNING_MESSAGE);
				}
				else if(null == actualFile || "".equals(actualFile))
				{
					JOptionPane.showMessageDialog(jFrame,"实际文件不能为空!","警告信息",JOptionPane.WARNING_MESSAGE);
				}
				else
				{
					
				}
			}
		});
		
		
		JPanel sortPane = new JPanel();
		sortPane.setLayout(null);
		sortPane.setBounds(10, 330, 770, 120);
		sortPane.setBorder(BorderFactory.createTitledBorder("执行SQL脚本文件"));
		container.add(sortPane);
    	
		JLabel inputLabel = new JLabel("文  件:");
		inputLabel.setBounds(60, 40, 80, 26);
		sortPane.add(inputLabel);
		
		final JTextField inputTextField = new JTextField();
		inputTextField.setBounds(120, 40, 200, 26);
		sortPane.add(inputTextField);
		
		JButton inputButton = new JButton("...");
		inputButton.setBounds(320, 40, 20, 26);
		sortPane.add(inputButton);
		inputButton.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				JFileChooser jFileChooser = new JFileChooser();
				 int returnVal = jFileChooser.showOpenDialog(jFrame); 
	             if (returnVal == JFileChooser.APPROVE_OPTION) 
	             { 
	                 File file = jFileChooser.getSelectedFile();               
	                 inputTextField.setText(file.getAbsolutePath());
	             }
			}
		});
    	
		
		
		
		
		JButton sortButton = new JButton("执行脚本");
		sortButton.setBounds(388, 40, 80, 26);//590, 80, 80, 26
		sortPane.add(sortButton);
		sortButton.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				String inputFile = inputTextField.getText();
				String outputFile = inputTextField.getText();
				String sequenceFlag = "";
				if(null == inputFile || "".equals(inputFile))
				{
					JOptionPane.showMessageDialog(jFrame,"输入文件不能为空!","警告信息",JOptionPane.WARNING_MESSAGE);
				}
				else if(null == outputFile || "".equals(outputFile))
				{
					JOptionPane.showMessageDialog(jFrame,"输出文件不能为空!","警告信息",JOptionPane.WARNING_MESSAGE);
				}
				else
				{
                   
				}
			}
		});
		
    	int width = 800;
    	int height = (int)(width * 0.618);
		jFrame.setSize(width,height);
		int x = (dimension.width - jFrame.getSize().width)/2;
		int y = (dimension.height - jFrame.getSize().height)/2;
		jFrame.setLocation(x, y);
		jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		jFrame.setResizable(false);
		jFrame.setVisible(true);
	}
}

 

你可能感兴趣的:(demo)