How To Right Align Using StringBuffer
Nov 4, 2014
public StringBuffer padSpaces(String first, String second)
{
final int MAX_SPACES = 75;
StringBuffer line = new StringBuffer(first);
int numSpaces = MAX_SPACES - first.length()- second.length();
for (int i = 0; i < numSpaces; i++)
line.append(" " );
line.append(second);
return line;
}
This is what I have so far but I can't find a way to align everything to the right .
View Replies
Oct 2, 2014
The code was,
messageLabel = new JLabel("Top buttons change the panel color and bottom radio buttons change the text color.");
messageLabel.setHorizontalTextPosition(SwingConstants.CENTER);
messageLabel.setVerticalAlignment(SwingConstants.CENTER);
The text always displays in top-center part of the center panel. i want to align it as center-center horizontally and vertically. The problem could be, bcoz the jlabel text is inside a constructor but im not sure. The whole code is
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ColorSample extends JFrame {
private JPanel TopPanel;
[Code] .....
View Replies
View Related
Mar 5, 2015
So, I've been working on a school project for a couple days, and I have my code written out but I can't fix the compile-time errors. The prompt for it is here:
Write two programs: one using the String class and one using the StringBuffer class. Your programs should store a set of Strings in an ArrayList and print those Strings in the order by which they are added. The output of your programs should create a complete sentence.
I am stuck on the first program.Here's my code for the first program:
Java Code:
import java.util.ArrayList;
public class SentenceNormal {
public static void main(String args[]) {
String n1 = "My ";
String n2 = "favorite ";
String n3 = "football ";
String n4 = "team ";
String n5 = "is ";
String n6 = "the ";
String n7 = "Seahawks";
[code]....
View Replies
View Related
Apr 25, 2013
I want to convert the StringBuffer in to String . I have used this code but gives compile error.
import java.io.*;
import java.util.*;
import javax.mail.*;
import java.sql.*;
public class REPLACE {
static StringBuffer s= new StringBuffer("ABCD");
public static void main(String args[]) throws Exception
[Code] ....
C:jdk1.6.0_04bin>javac REPLACE.java
REPLACE.java:15: cannot find symbol
symbol : method to_String()
location: class java.lang.StringBuffer
rep = s.to_String();
^
1 error
View Replies
View Related
Apr 4, 2014
" In terms of methods supported by the classes, the methods of StringBuffer and StringBuilder are identical. They only differ in whether the methods are synchronized or not. " - Oracle Certified Associate Java SE7 Programmer Study Guide
What does synchronized mean in this context?
View Replies
View Related