Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JTextField;
- import javax.swing.JComboBox;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class Tela extends JFrame {
- private JPanel contentPane;
- private JTextField numero;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Tela frame = new Tela();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public static void verificar(){
- }
- /**
- * Create the frame.
- */
- public Tela() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JPanel panel = new JPanel();
- panel.setBounds(10, 0, 414, 261);
- contentPane.add(panel);
- panel.setLayout(null);
- JLabel lblNumero = new JLabel("Numero:");
- lblNumero.setBounds(10, 11, 53, 14);
- panel.add(lblNumero);
- numero = new JTextField();
- numero.setBounds(73, 8, 155, 20);
- panel.add(numero);
- numero.setColumns(10);
- JLabel lblDaBase = new JLabel("Da base:");
- lblDaBase.setBounds(10, 39, 67, 14);
- panel.add(lblDaBase);
- JComboBox dabase = new JComboBox();
- dabase.setModel(new DefaultComboBoxModel(new String[] {"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"}));
- dabase.setBounds(73, 39, 40, 20);
- panel.add(dabase);
- JLabel lblParaBase = new JLabel("Para base:");
- lblParaBase.setBounds(10, 64, 67, 14);
- panel.add(lblParaBase);
- JComboBox parabase = new JComboBox();
- parabase.setModel(new DefaultComboBoxModel(new String[] {"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"}));
- parabase.setBounds(73, 64, 40, 20);
- panel.add(parabase);
- JLabel resposta = new JLabel("");
- resposta.setBounds(10, 95, 394, 20);
- panel.add(resposta);
- JButton btnConverter = new JButton("Converter");
- btnConverter.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String n = numero.getText();
- String res = "";
- int num = 0 , i = 0;
- int baseOrigem = Integer.parseInt(dabase.getSelectedItem().toString());
- int baseDestino = Integer.parseInt(parabase.getSelectedItem().toString());
- if(!CDB.existeNaBase(n, baseOrigem)){
- resposta.setText("O numero "+n+" não existe na base "+baseOrigem);
- }else{
- while(i < n.length()){
- num = num + (CDB.comparar(String.valueOf(n.charAt(i)))) * (int) Math.pow(baseOrigem, n.length() -1- i);
- i++;
- }
- resposta.setText(String.valueOf("O numero "+n+" na base "+baseOrigem+" equivale ao numero "+CDB.converterBase(num,baseDestino)+" na base "+baseDestino));
- }
- System.out.println("O numero "+n+" na base "+baseOrigem+" equivale ao numero "+CDB.converterBase(num,baseDestino)+" na base "+baseDestino);
- }
- });
- parabase.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- String n = numero.getText();
- String res = "";
- int num = 0 , i = 0;
- int baseOrigem = Integer.parseInt(dabase.getSelectedItem().toString());
- int baseDestino = Integer.parseInt(parabase.getSelectedItem().toString());
- if(!CDB.existeNaBase(n, baseOrigem)){
- resposta.setText("O numero "+n+" não existe na base "+baseOrigem);
- }else{
- while(i < n.length()){
- num = num + (CDB.comparar(String.valueOf(n.charAt(i)))) * (int) Math.pow(baseOrigem, n.length() -1- i);
- i++;
- }
- resposta.setText(String.valueOf("O numero "+n+" na base "+baseOrigem+" equivale ao numero "+CDB.converterBase(num,baseDestino)+" na base "+baseDestino));
- }
- System.out.println("O numero "+n+" na base "+baseOrigem+" equivale ao numero "+CDB.converterBase(num,baseDestino)+" na base "+baseDestino);
- }
- });
- btnConverter.setBounds(238, 7, 103, 23);
- panel.add(btnConverter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement