I have written the following code.I need to convert it to GUI.

import java.awt.*; 
import java.applet.*; 
import java.awt.event.*; 

public class CompString{
    public static void main(String[] args) {
        System.out.println("Enter two strings:");
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Please enter first string:");
        String str1 = bf.readLine();
        System.out.println("Please enter second string:");
        String str2 = bf.readLine();
        if (string2.compareTo(string1) > 0)
                 System.out.println(str2 + " is greater than " + str1);
            System.out.println(str1 + " is greater than " + str2);


Edited by mike_2000_17: Fixed formatting

7 Years
Discussion Span
Last Post by BestJewSinceJC

Who's stopping you then ? Put out two labels mentioning "Enter string 1" "Enter string 2", put out two textboxes allowing the user to input the same. Use a label to finally show the result of the comparison. What was so difficult in this. Take a look at the Swing/AWT tutorials if you are finding yourself uncomfortable with GUI development.

And start using code tags, you have already 12 posts.

Votes + Comments
"What's stopping you?" was my thought exactly as well :)

My dear Friend,

I think you are a beginner in java like me. so i am giving you steps to create Swing application

1).import all swing library packegs like
import javax.swing.*;
2).then create class which extends JFrame class
3).define two private JTextField as instance object
4).one private JLable as instance object
5).then initialize all object with new keyword and specific constructor
6).write main method
7).create object of that swing class or using this keyword call setVisible(true) method and setSize(width,height) if window.


swing app. compleate then compile that .java file from command prompt using javac

run that .class file using java command


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.