Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Sebuah program yang dapat format text menjadi Upper-case, Lower-case
- * maupun case tersebut di invert
- *
- * @author Daffa Tristan Firdaus
- * @version 14 Januari 2021
- */
- import javax.swing.*;
- import javax.swing.JFrame;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class UpperLowerCaseConverter extends JFrame
- {
- private JButton button1, button2, button3, button4, button5, button6;
- private JTextArea textarea1, textarea2;
- public static String invertCase(String str)
- {
- char[] chars = str.toCharArray();
- for (int i = 0; i < chars.length; i++) {
- chars[i] = Character.isUpperCase(chars[i])
- ? Character.toLowerCase(chars[i])
- : Character.toUpperCase(chars[i]);
- }
- return new String(chars);
- }
- public UpperLowerCaseConverter() {
- JFrame f = new JFrame("Upper-case Lower-case Converter");
- f.setTitle("Upper-case Lower-case Converter");
- f.setSize(500,400);
- JPanel contentPane = new JPanel(null);
- contentPane.setPreferredSize(new Dimension(500,400));
- contentPane.setBackground(Color.DARK_GRAY);
- button1 = new JButton();
- button1.setBounds(18,176,120,35);
- button1.setBackground(new Color(214,217,223));
- button1.setForeground(new Color(0,0,0));
- button1.setEnabled(true);
- button1.setFont(new Font("sansserif",0,12));
- button1.setText("Upper-Case");
- button1.setVisible(true);
- button1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String str = textarea1.getText();
- textarea2.setText(str.toUpperCase());
- }
- });
- button2 = new JButton();
- button2.setBounds(145,176,120,35);
- button2.setBackground(new Color(214,217,223));
- button2.setForeground(new Color(0,0,0));
- button2.setEnabled(true);
- button2.setFont(new Font("sansserif",0,12));
- button2.setText("Lower-Case");
- button2.setVisible(true);
- button2.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String str = textarea1.getText();
- textarea2.setText(str.toLowerCase());
- }
- });
- button3 = new JButton();
- button3.setBounds(404,280,90,35);
- button3.setBackground(new Color(214,217,223));
- button3.setForeground(new Color(0,0,0));
- button3.setEnabled(true);
- button3.setFont(new Font("sansserif",0,12));
- button3.setText("Copy");
- button3.setVisible(true);
- button3.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- textarea2.selectAll();
- textarea2.copy();
- }
- });
- button4 = new JButton();
- button4.setBounds(404,75,90,35);
- button4.setBackground(new Color(214,217,223));
- button4.setForeground(new Color(0,0,0));
- button4.setEnabled(true);
- button4.setFont(new Font("sansserif",0,12));
- button4.setText("Paste");
- button4.setVisible(true);
- button4.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- textarea1.paste();
- }
- });
- button5 = new JButton();
- button5.setBounds(273,176,120,35);
- button5.setBackground(new Color(214,217,223));
- button5.setForeground(new Color(0,0,0));
- button5.setEnabled(true);
- button5.setFont(new Font("sansserif",0,12));
- button5.setText("Invert Case");
- button5.setVisible(true);
- button5.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String str = textarea1.getText();
- textarea2.setText(invertCase(str));
- }
- });
- button6 = new JButton();
- button6.setBounds(404,30,90,35);
- button6.setBackground(new Color(214,217,223));
- button6.setForeground(new Color(0,0,0));
- button6.setEnabled(true);
- button6.setFont(new Font("sansserif",0,12));
- button6.setText("Clear");
- button6.setVisible(true);
- button6.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- textarea1.setText("");
- }
- });
- textarea1 = new JTextArea();
- textarea1.setBounds(18,18,380,150);
- textarea1.setBackground(new Color(255,255,255));
- textarea1.setForeground(new Color(0,0,0));
- textarea1.setEnabled(true);
- textarea1.setFont(new Font("sansserif",0,12));
- textarea1.setText("Input");
- textarea1.setBorder(BorderFactory.createBevelBorder(1));
- textarea1.setVisible(true);
- textarea2 = new JTextArea();
- textarea2.setBounds(18,220,380,150);
- textarea2.setBackground(new Color(255,255,255));
- textarea2.setForeground(new Color(0,0,0));
- textarea2.setEnabled(true);
- textarea2.setFont(new Font("sansserif",0,12));
- textarea2.setText("Output");
- textarea2.setBorder(BorderFactory.createBevelBorder(1));
- textarea2.setVisible(true);
- contentPane.add(button1);
- contentPane.add(button2);
- contentPane.add(button3);
- contentPane.add(button4);
- contentPane.add(button5);
- contentPane.add(button6);
- contentPane.add(textarea1);
- contentPane.add(textarea2);
- f.add(contentPane);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- f.setLocationRelativeTo(null);
- f.pack();
- f.setVisible(true);
- }
- public static void main(String[] args){
- UpperLowerCaseConverter ulcc = new UpperLowerCaseConverter();
- }
- }
Add Comment
Please, Sign In to add comment