Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.EventQueue;
- import java.awt.Font;
- import java.awt.TextArea;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- import javax.swing.border.EmptyBorder;
- public class Power extends JFrame {
- private static final long serialVersionUID = 1L;
- private JPanel contentPane;
- private JTextField textField;
- private JTextField textField_1;
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Power frame = new Power();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public Power() {
- setBackground(Color.BLACK);
- setForeground(Color.CYAN);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBackground(Color.BLACK);
- contentPane.setForeground(Color.CYAN);
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel lblNewLabel = new JLabel("Inserirt base");
- lblNewLabel.setBackground(Color.BLACK);
- lblNewLabel.setForeground(Color.CYAN);
- lblNewLabel.setBounds(23, 23, 73, 14);
- contentPane.add(lblNewLabel);
- JLabel lblNewLabel_1 = new JLabel("Inserirt exponent");
- lblNewLabel_1.setBackground(Color.BLACK);
- lblNewLabel_1.setForeground(Color.CYAN);
- lblNewLabel_1.setBounds(283, 23, 112, 14);
- contentPane.add(lblNewLabel_1);
- textField = new JTextField();
- textField.setBackground(Color.BLACK);
- textField.setForeground(Color.CYAN);
- textField.setBounds(10, 48, 86, 20);
- contentPane.add(textField);
- textField.setColumns(10);
- textField_1 = new JTextField();
- textField_1.setBackground(Color.BLACK);
- textField_1.setForeground(Color.CYAN);
- textField_1.setBounds(293, 48, 86, 20);
- contentPane.add(textField_1);
- textField_1.setColumns(10);
- TextArea textArea = new TextArea();
- textArea.setRows(1);
- textArea.setEditable(false);
- textArea.setBackground(Color.BLACK);
- textArea.setForeground(Color.CYAN);
- textArea.setBounds(10, 74, 414, 178);
- contentPane.add(textArea);
- JButton btnNewButton = new JButton("Calculate");
- btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 19));
- btnNewButton.setBackground(Color.BLACK);
- btnNewButton.setForeground(Color.CYAN);
- btnNewButton.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- textArea.setText("");
- int a=Integer.parseInt(textField.getText());
- int b=Integer.parseInt(textField_1.getText());
- for(int c=0;c<b+1;c++){
- textArea.setText(textArea.getText()+a+" ^ "+c+" = "+(long)Math.pow(a,c)+"\n");
- }
- }
- });
- btnNewButton.setBounds(127, 27, 119, 43);
- contentPane.add(btnNewButton);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement