Advertisement
Dar954826

Power[ENG].java

Mar 11th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.01 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.EventQueue;
  3. import java.awt.Font;
  4. import java.awt.TextArea;
  5. import java.awt.event.MouseAdapter;
  6. import java.awt.event.MouseEvent;
  7.  
  8. import javax.swing.JButton;
  9. import javax.swing.JFrame;
  10. import javax.swing.JLabel;
  11. import javax.swing.JPanel;
  12. import javax.swing.JTextField;
  13. import javax.swing.border.EmptyBorder;
  14.  
  15. public class Power extends JFrame {
  16.     private static final long serialVersionUID = 1L;
  17.     private JPanel contentPane;
  18.     private JTextField textField;
  19.     private JTextField textField_1;
  20.     public static void main(String[] args) {
  21.         EventQueue.invokeLater(new Runnable() {
  22.             public void run() {
  23.                 try {
  24.                     Power frame = new Power();
  25.                     frame.setVisible(true);
  26.                 } catch (Exception e) {
  27.                     e.printStackTrace();
  28.                 }
  29.             }
  30.         });
  31.     }
  32.     public Power() {
  33.         setBackground(Color.BLACK);
  34.         setForeground(Color.CYAN);
  35.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  36.         setBounds(100, 100, 450, 300);
  37.         contentPane = new JPanel();
  38.         contentPane.setBackground(Color.BLACK);
  39.         contentPane.setForeground(Color.CYAN);
  40.         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  41.         setContentPane(contentPane);
  42.         contentPane.setLayout(null);
  43.        
  44.         JLabel lblNewLabel = new JLabel("Inserirt base");
  45.         lblNewLabel.setBackground(Color.BLACK);
  46.         lblNewLabel.setForeground(Color.CYAN);
  47.         lblNewLabel.setBounds(23, 23, 73, 14);
  48.         contentPane.add(lblNewLabel);
  49.        
  50.         JLabel lblNewLabel_1 = new JLabel("Inserirt exponent");
  51.         lblNewLabel_1.setBackground(Color.BLACK);
  52.         lblNewLabel_1.setForeground(Color.CYAN);
  53.         lblNewLabel_1.setBounds(283, 23, 112, 14);
  54.         contentPane.add(lblNewLabel_1);
  55.        
  56.         textField = new JTextField();
  57.         textField.setBackground(Color.BLACK);
  58.         textField.setForeground(Color.CYAN);
  59.         textField.setBounds(10, 48, 86, 20);
  60.         contentPane.add(textField);
  61.         textField.setColumns(10);
  62.        
  63.         textField_1 = new JTextField();
  64.         textField_1.setBackground(Color.BLACK);
  65.         textField_1.setForeground(Color.CYAN);
  66.         textField_1.setBounds(293, 48, 86, 20);
  67.         contentPane.add(textField_1);
  68.         textField_1.setColumns(10);
  69.        
  70.         TextArea textArea = new TextArea();
  71.         textArea.setRows(1);
  72.         textArea.setEditable(false);
  73.         textArea.setBackground(Color.BLACK);
  74.         textArea.setForeground(Color.CYAN);
  75.         textArea.setBounds(10, 74, 414, 178);
  76.         contentPane.add(textArea);
  77.        
  78.         JButton btnNewButton = new JButton("Calculate");
  79.         btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 19));
  80.         btnNewButton.setBackground(Color.BLACK);
  81.         btnNewButton.setForeground(Color.CYAN);
  82.         btnNewButton.addMouseListener(new MouseAdapter() {
  83.             @Override
  84.             public void mouseClicked(MouseEvent arg0) {
  85.                
  86.                 textArea.setText("");
  87.                 int a=Integer.parseInt(textField.getText());
  88.                 int b=Integer.parseInt(textField_1.getText());
  89.                 for(int c=0;c<b+1;c++){
  90.                     textArea.setText(textArea.getText()+a+" ^ "+c+" = "+(long)Math.pow(a,c)+"\n");
  91.                 }
  92.                
  93.                
  94.                
  95.             }
  96.         });
  97.         btnNewButton.setBounds(127, 27, 119, 43);
  98.         contentPane.add(btnNewButton);
  99.        
  100.        
  101.        
  102.        
  103.        
  104.        
  105.        
  106.        
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement