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

📄 mainpanel.java

📁 LCD字模转换工具
💻 JAVA
字号:
/*
 * MainPanel.java
 *
 * Created on 2008年6月4日, 下午9:58
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package lcdtransformer;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author Administrator
 */
public class MainPanel extends JPanel
{
    
    /** Creates a new instance of MainPanel */
    public MainPanel() 
    {
        okButton = new JButton( "OK" );
        okButton.addActionListener( new OKAction() );
        output = new JTextField( "0x00" );
        buttons = new JRadioButton[ 8 ][ 5 ];
        buttonPanel = new JPanel();
        buttonPanel.setLayout( new GridLayout( 8, 5 ) );
        
        for( int i = 0; i < 8; i++ )
            for( int j = 0; j < 5; j++ )
            {
                buttons[ i ][ j ] = new JRadioButton();
                buttonPanel.add( buttons[ i ][ j ] );
            }
        setLayout( new BorderLayout() );
        add( output, BorderLayout.NORTH );
        add( buttonPanel, BorderLayout.CENTER );
        add( okButton, BorderLayout.SOUTH );
    }
    
    public class OKAction implements ActionListener
    {
        public void actionPerformed(ActionEvent e) 
        {
            String out = new String();
            String binary = new String();
            
            for( int i = 0; i < 5; i++ )
            {
                binary = "";
                for( int j = 7; j >= 0 ; j-- )
                {
                    if( buttons[ j ][ i ].isSelected() )
                        binary += "1";
                    else
                        binary += "0";
                }
                out += "0x" + Integer.toHexString( Integer.parseInt( binary, 2 ) );
                out += ",";
            }
            
            output.setText( out );
        }
        
    }
    
    private JTextField output;
    private JRadioButton buttons[][];
    private JButton okButton;
    private JPanel buttonPanel;
}

⌨️ 快捷键说明

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