Advertisement
Dar954826

Tables[ENG].java

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