Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Need help finishing my program

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help finishing my program

    Hello Community, looking to see if anyone can help me finish my code. I am making a program that turns upper case to lower case and lower case to upper case at the push of the button. I have everything set up 2 text fields, 1 button. i am stuck and have no clue how to make it do what i want. i have tried a few things but nothing seems to work. Can anyone get me going in the right direction. Thanks
    Here is my code so far:

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.util.*;
    import java.io.*;
     
    public class Ulcase
    {
     
    	JLabel l1,l2;
    	JTextField tf1,tf2;
    	JButton b1;
     
    public static void main(String[] args) 
    	{
     
    	new Ulcase();
     
    	}
     
    public Ulcase()
    	{
    		JFrame frame1 = new JFrame();
    		frame1.setTitle("Converting Cases"); 			
    		frame1.setSize(700,75);              		
     
    		JLabel l1 = new JLabel("Word to Convert");	
    		JLabel l2 = new JLabel("Converted Word");	
     
    		JTextField tf1 = new JTextField(10);
    		JTextField tf2 = new JTextField(5);
     
    		JButton b1 = new JButton("Press To Convert");
     
    		b1.addActionListener(new ActionListener() {
     
     			public void actionPerformed(ActionEvent e)
                {
     
     
                }
    		});
     
     
    		tf2.setEditable(false);
     
    		Container pane = frame1.getContentPane();
    		pane.setLayout(new GridLayout(1,3) );
     
    		pane.add(l1);
    		pane.add(tf1);
    		pane.add(l2);
    		pane.add(tf2);
    		pane.add(b1);
     
     
    		frame1.setLocationRelativeTo(null);
    		frame1.setDefaultCloseOperation(frame1.EXIT_ON_CLOSE);
    		frame1.setVisible(true);
     
    	}
    }


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Need help finishing my program

    i am stuck and have no clue how to make it do what i want. i have tried a few things but nothing seems to work.
    Forget the code for a moment, because you need a plan (quite comprehensive and precise) before you can write any code.

    Suppose you were given the task of swapping the case of the characters in a string you were presented with. What would you - rather than a computer - do? What are the steps you would follow, steps that would work for any string whatsoever: "cAsE", "c453", "", etc.

    Once you have a clear sequence of steps have a look in the API documentation - especially that of the String and Character class - for ways of expressing that plan in code.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help finishing my program

    Well i have steps that i am trying to follow but i am still at the beginner stage so even though i kind of know the steps, im still lost. i been at it for a few hours. Which is why i signed up to the forums and posted for help. I know i am missing something but it was hard enough for me to get to this point. I know you are trying to help me Thank you.

  4. #4
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help finishing my program

    Ok i got it to change the whole input into uppercase, so im almost done. im just stuck again at how to change uppercase to lower case.

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.util.*;
    import java.io.*;
     
    public class Window extends JFrame implements ActionListener
    {
      private JTextField t1,t2;
      private JLabel myLab;
      private JButton b1, b2;
      private Container c;
     
    public Window()
    	{				
     		c=getContentPane();
      		c.setLayout(new FlowLayout());
      		c.setBackground(Color.WHITE);
     
      		myLab= new JLabel();
      		myLab.setText("Word to Convert:  ");
      		c.add(myLab);
     
      		t1=new JTextField(15);
      		t1.setBackground(Color.WHITE);
      		c.add(t1);
     
      		t2=new JTextField(20);
      		t2.setEditable(false);
      		c.add(t2);
     
      		b1=new JButton("Convert");
      		b1.addActionListener(this);
      		c.add(b1);
     
      	}
     
    public void actionPerformed(ActionEvent e)
    	{
      		String name = t1.getText();
    	 	t2.setText(name);
         	        t1.setText("");
    		name = name.toUpperCase();
    		t2.setText(name);
     
    	}
     
    public static void main(String[] args)
    	{
       	Window h1= new Window();
    		h1.setTitle("Converting Cases");
    		h1.setLocationRelativeTo(null);
    	 	h1.setSize(400,100);
    	 	h1.setVisible(true);
    	 	h1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    	} 
    }

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need help finishing my program

    how to change uppercase to lower case.
    The String class has a method that will do that.

    However your code does not solve your problem. You need to make a plan as recommended in post#2 before you write the code. Writing code BEFORE you know what the code is supposed to do can be a waste of time.
    Last edited by Norm; April 6th, 2012 at 06:13 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Member
    Join Date
    Jun 2011
    Posts
    182
    My Mood
    Where
    Thanks
    15
    Thanked 8 Times in 8 Posts

    Default Re: Need help finishing my program

    I would recommend two buttons. One calls String.toUpperCase() and the other calls String.toLowerCase() on the text field's String value when pressed.

Similar Threads

  1. Program to launch and mirror another program
    By hayate in forum Java Theory & Questions
    Replies: 13
    Last Post: March 9th, 2012, 12:47 AM
  2. Replies: 11
    Last Post: February 10th, 2012, 05:38 PM
  3. Need help finishing code. List Building...
    By Margaret_Girl87 in forum Object Oriented Programming
    Replies: 1
    Last Post: November 30th, 2011, 06:09 PM
  4. Beginner. Need Help finishing a simple Shoot em up game ASAP!!!!
    By cbock55 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 2nd, 2011, 08:13 AM
  5. Help with class program!!! STUCK! Program not doing what I Want!!!
    By sketch_flygirl in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2011, 07:29 AM