Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. import java.awt.Dimension;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.awt.event.KeyEvent;
  5. import java.awt.event.KeyListener;
  6.  
  7. import javax.swing.*;
  8.  
  9. public class ButtonsNText extends JPanel {
  10.    
  11.    JTextField TextLine = new JTextField();
  12.    
  13.    ButtonGroup group = new ButtonGroup();
  14.    JToggleButton UpperCaseButton = new JToggleButton("Upper case");
  15.    JToggleButton LowerCaseButton = new JToggleButton("Lower case");
  16.    
  17.    JCheckBox ContinuousButton = new JCheckBox("Continous");
  18.    
  19.    public ButtonsNText() {
  20.      
  21.       TextLine.setPreferredSize(new Dimension(250,25));
  22.      
  23.       group.add(UpperCaseButton);
  24.       group.add(LowerCaseButton);
  25.      
  26.      
  27.       this.add(TextLine);
  28.       this.add(UpperCaseButton);
  29.       this.add(LowerCaseButton);
  30.       this.add(ContinuousButton);
  31.      
  32.       TextLine.addKeyListener(new TextLineListener());
  33.       UpperCaseButton.addActionListener(new ButtonListener());
  34.       LowerCaseButton.addActionListener(new ButtonListener());
  35.  
  36.    }
  37.    
  38.    private class TextLineListener implements KeyListener {
  39.       public void keyPressed(KeyEvent e) {  
  40.       }
  41.       public void keyReleased(KeyEvent e) {
  42.          if(ContinuousButton.isSelected()){
  43.             if(UpperCaseButton.isSelected()){
  44.                TextLine.setText(TextLine.getText().toUpperCase());
  45.             }else{
  46.                TextLine.setText(TextLine.getText().toLowerCase());
  47.             }
  48.          }
  49.       }
  50.       public void keyTyped(KeyEvent e) {  
  51.       }
  52.    }
  53.    
  54.    
  55.    
  56.    private class ButtonListener implements ActionListener {
  57.       public void actionPerformed(ActionEvent e) {
  58.          if(UpperCaseButton.isSelected()){
  59.             TextLine.setText(TextLine.getText().toLowerCase());
  60.          }else{
  61.             TextLine.setText(TextLine.getText().toUpperCase());
  62.          }
  63.       }
  64.      
  65.    }
  66.    
  67.    
  68.    public static void main(String[] args) {
  69.      
  70.       JFrame frame = new JFrame("MMI Oppgave 1");
  71.       frame.setContentPane(new ButtonsNText());
  72.       frame.pack();
  73.       frame.setVisible(true);
  74.      
  75.    }
  76.    
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement