Select Menu

Combined Post

Mag Posts

Theme images by konradlew. Powered by Blogger.

Blogger templates

Blogger news

Facebook

Advertising

Blogroll

Popular Posts

Combined Posts 2

Mag Post 2

2 Column Post

Simple Post

Simple Post 2

New Carousel

Video Posts

» » Java Code for a Capitalizer program


SLVIKI 9:06 PM 0

Here is the output of the java program






Here is the java code for the program


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 * A trivial GUI application for capitalizing strings.
 * You get to type in strings into a textarea and press
 * buttons to make the string all lowercase or all uppercase.
 */
@SuppressWarnings("serial")
public class Capitalizer {

     public static void main(String[] args) {
        String initialText = "Type your Text here. Then press a button";
        final JTextArea area = new JTextArea(initialText, 8, 50);

        JPanel buttonPanel = new JPanel();
        buttonPanel.add(new JButton(new AbstractAction("To Lower Case") {
            public void actionPerformed(ActionEvent e) {
                area.setText(area.getText().toLowerCase());
            }
        }));
        buttonPanel.add(new JButton(new AbstractAction("To Upper Case") {
            public void actionPerformed(ActionEvent e) {
                area.setText(area.getText().toUpperCase());
            }
        }));

        JFrame frame = new JFrame("Capitalizer");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER);
        frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
        frame.pack();
        frame.setVisible(true);
    }
}

enjoy!

«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply