Problrm in compiling this program

pLEASE LET ME KNOW WHERE i AM WRONG IN COMPILING THIS CODE....
CAN WE CREATE A NEW PUBLIC STATIC OBJECT OF A CLASS UNDER MAIN??
pLZ HELP
import java.lang.*;
import java.util.*;
import realcom.real.*;//FORGET ABT THIS
public class test{         //
public static void main(Strings args[]){
public static real r= new real();
String abc="this is right" ;
String result=r.taken(abc);
System.out.println(abc);
System.out.println(result);

Whats the point of declaring a method scoped variable public - or static for that matter?
public static real r = new real();
Should be:
real r = new real();
Is this some kind of trick question?

Similar Messages

  • Anyone can compile this program?Duke will be rewarded

    Anyone can help me compile this program..I try debugging a lot of time but it is not working!
    import java.lang.*;
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class ChatApplet extends Applet implements ActionListener,Runnable
    String user;
    String msg;
         public void init() {
              super.init();
              //{{INIT_CONTROLS
              setLayout(new BorderLayout(0,0));
              addNotify();
              resize(518,347);
              setBackground(new Color(12632256));
    msgbox = new java.awt.TextArea("",2,0,TextArea.SCROLLBARS_NONE);
              msgbox.setEditable(false);
    msgbox.disable();
    //msgbox.hide();
              msgbox.reshape(0,0,380,216);
              add(msgbox);
              idbox = new java.awt.TextField();
              idbox.reshape(84,288,284,24);
              add(idbox);
              button1 = new java.awt.Button("EnterRoom");
              button1.reshape(384,288,72,21);
              add(button1);
    list = new java.awt.List();
    //list.TOP_ALIGNMENT();
    //list.disable();
    list = new java.awt.List(5);
    list.add("#Default User"+"\n");
    list.reshape(384,24,128,196);
    list.setFont(new Font("Helvetica", Font.BOLD, 12));
    add(list);
              label2 = new java.awt.Label("Members");
              label2.reshape(396,0,100,19);
              add(label2);
              label1 = new java.awt.Label("UserName");
              label1.reshape(0,288,72,27);
              add(label1);
              textbox = new java.awt.TextField();
              textbox.reshape(84,240,431,44);
              add(textbox);
              label3 = new java.awt.Label("EnterText");
              label3.reshape(0,252,72,25);
              add(label3);
    //uf = new UserFrame();
              button1.addActionListener(this);
    idbox.addActionListener(this);
    textbox.addActionListener(this);
    list.addActionListener(this);
    public void actionPerformed(ActionEvent ae)
              if(ae.getSource()==idbox)
    user = idbox.getText()+"\n";
    list.addItem(user.trim());
    idbox.setText("");
                             msgbox.append(user+" HAS JOINED THE GROUP");
         if(ae.getSource().equals(button1))
    user = idbox.getText()+"\n";
    list.addItem(user.trim());
    idbox.setText("");
                             msgbox.append(user+" HAS JOINED THE GROUP");
    if(ae.getSource().equals(textbox))
    msg = textbox.getText();
    msgbox.append(msg+"\n");
    textbox.setText("");
    if(ae.getSource().equals(list))
    String l = list.getSelectedItem();
                             //uf.setTitle(l);
                             //Frame i[] = uf.getFrames();
                             //uf.setVisible(true);
    public void start()
    if(vt == null)
    vt = new Thread(this,getClass().getName());
    vt.start();
    public void run()
    try{
    for(int i=0;i<10;i++)
    msgbox.append("One stop Java source code - www.globalleafs.com"+"\n");
    msgbox.setForeground(Color.red);
    vt.sleep(30000);
    vt.resume();
    }catch(Exception e){e.printStackTrace();}
         java.awt.TextArea msgbox;
         java.awt.TextField idbox;
         java.awt.Button button1;
    java.awt.List list;
    java.awt.Label label2;
         java.awt.Label label1;
         java.awt.TextField textbox;
         java.awt.Label label3;
    private Thread vt;

    The program compiles over here. It just has some deprecation warnings ...or is that what you wanted debugged?
    Don't use reshape() ...I think in AWT you should now use setBounds();
    Don't use list.addItem(); ...looks like the API steers us to list.add();
    Don't use Thread.resume() ...I don't think there is a replacement (unneccessary?).
    Gee, this program must have ran the chat program in Ford's old model T ... !! (??)

  • Help! I can't compile this program

    I copied the following program from E.Harold's book,Java Network Programming,online edition.The file name is SMTPClient.java.Its function is sending simple mails.
    When I compiled the file,there were 6 error messages indicating that the first 6 lines of code were wrong.The reasons are something like "class" or "interface" needed.
    Can anybody give me some advice?
    Source file:
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class SMTPClient extends JFrame {
    private JButton sendButton = new JButton("Send Message");
    private JLabel fromLabel = new JLabel("From: ");
    private JLabel toLabel = new JLabel("To: ");
    private JLabel hostLabel = new JLabel("SMTP Server: ");
    private JLabel subjectLabel = new JLabel("Subject: ");
    private JTextField fromField = new JTextField(40);
    private JTextField toField = new JTextField(40);
    private JTextField hostField = new JTextField(40);
    private JTextField subjectField = new JTextField(40);
    private JTextArea message = new JTextArea(40, 72);
    private JScrollPane jsp = new JScrollPane(message);
    public SMTPClient() {
    super("SMTP Client");
    Container contentPane = this.getContentPane();
    contentPane.setLayout(new BorderLayout());
    JPanel labels = new JPanel();
    labels.setLayout(new GridLayout(4, 1));
    labels.add(hostLabel);
    JPanel fields = new JPanel();
    fields.setLayout(new GridLayout(4, 1));
    String host = System.getProperty("mail.host", "");
    hostField.setText(host);
    fields.add(hostField);
    labels.add(toLabel);
    fields.add(toField);
    String from = System.getProperty("mail.from", "");
    fromField.setText(from);
    labels.add(fromLabel);
    fields.add(fromField);
    labels.add(subjectLabel);
    fields.add(subjectField);
    Box north = Box.createHorizontalBox();
    north.add(labels);
    north.add(fields);
    contentPane.add(north, BorderLayout.NORTH);
    message.setFont(new Font("Monospaced", Font.PLAIN, 12));
    contentPane.add(jsp, BorderLayout.CENTER);
    JPanel south = new JPanel();
    south.setLayout(new FlowLayout(FlowLayout.CENTER));
    south.add(sendButton);
    sendButton.addActionListener(new SendAction());
    contentPane.add(south, BorderLayout.SOUTH);
    this.pack();
    class SendAction implements ActionListener {
    public void actionPerformed(ActionEvent evt) {
    try {
    Properties props = new Properties();
    props.put("mail.host", hostField.getText());
    Session mailConnection = Session.getInstance(props, null);
    final Message msg = new MimeMessage(mailConnection);
    Address to = new InternetAddress(toField.getText());
    Address from = new InternetAddress(fromField.getText());
    msg.setContent(message.getText(), "text/plain");
    msg.setFrom(from);
    msg.setRecipient(Message.RecipientType.TO, to);
    msg.setSubject(subjectField.getText());
    // This can take a non-trivial amount of time so
    // spawn a thread to handle it.
    Runnable r = new Runnable() {
    public void run() {
    try {
    Transport.send(msg);
    catch (Exception ex) {
    ex.printStackTrace();
    Thread t = new Thread(r);
    t.start();
    message.setText("");
    catch (Exception ex) {
    // I should really bring up a more specific error dialog here.
    ex.printStackTrace();
    public static void main(String[] args) {
    SMTPClient client = new SMTPClient();
    // Next line requires Java 1.3 or later. I want to set up the
    // exit behavior here rather than in the constructor since
    // other programs that use this class may not want to exit
    // the application when the SMTPClient window closes.
    client.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    client.show();
    Message was edited by:
    oscarhua

    1:install Java SE,set the path variable to the directory of the bin folder(including bin).
    2:download the JavaMail 1.4 release from http://java.sun.com/products/javamail/downloads/index.html
    3:extract the downloaded file to any location and add the directory of its mail.jar file to classpath.
    4:download the JavaBeans Activation Framework 1.1release from
    http://java.sun.com/products/javabeans/jaf/downloads/index.html#download
    5:extract the downloaded file to any location and add the directory of its activation.jar file to classpath.
    then everything goes smoothly
    You inspired me and voronetskyy told me exactly what to do,so thak both of you again!:-)
    Message was edited by:
    oscarhua

  • I am not able to compile this program because it has an compile error.

    Please identify the problem and offer and/or correct the problem.+_
    Thank you very much for helping a new java wana_be programmer!+_
    Below is the source code:+_
    *===================*_
    import java.awt.*;
    import java.awt.MediaTracker;
    import java.awt.event.*;
    import com.sun.image.codec.jpeg.*;
    import java.awt.image.BufferedImage;
    import java.awt.image.DataBuffer;
    import java.awt.geom.GeneralPath;
    import java.io.*;
    import javax.swing.*;
    import javax.imageio.*;
    import java.net.URL;
    public class JavaPicture{
    public BufferedImage bimg;
    public JFrame shower = new JFrame();
    public ImageIcon imgIcon;
    public Canvas canvas;
    public Image image;
    * Constructor
    public void JavaPicture(){
    //No picture, no values
    public int getWidth(){
    return bimg.getWidth();
    public int getHeight(){
    return bimg.getHeight();
    * Load image
    public boolean loadImage(String filename){
    try{
    /*bimg = null;
    filename = "file://" + filename;
    URL u = new URL(filename);
    File f = new File(u.getPath());
    bimg = ImageIO.read(f);
    Toolkit toolkit = Toolkit.getDefaultToolkit();
                   image = toolkit.getImage(filename);
                   MediaTracker mediaTracker = new MediaTracker(shower);
                   mediaTracker.addImage(image, 0);
                   try
                        mediaTracker.waitForID(0);
                   catch (InterruptedException ie)
                        //The file did not load
                        System.err.println(ie);
                   bimg = new BufferedImage(image.getWidth(null), image.getHeight(null), bimg.TYPE_INT_RGB);
                   Graphics g = bimg.getGraphics();
                   g.drawImage(image, 0, 0, null);
    return true;
    catch (Exception e) {return false;}
    public void createNewImage(int width, int height){
         bimg = null;
         bimg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    public void repaintImage(){
    if (shower.isVisible()){
    imgIcon.setImage(bimg.getScaledInstance(bimg.getWidth(), bimg.getHeight(), Image.SCALE_FAST));
    shower.repaint();
    public void showPictureWithTitle(String s){
    if (shower.isVisible()){
    imgIcon.setImage(bimg.getScaledInstance(bimg.getWidth(), bimg.getHeight(), Image.SCALE_FAST));
    shower.setTitle(s);
    shower.repaint();
    else {
    shower = new JFrame(s);
    imgIcon = new ImageIcon(bimg.getScaledInstance(bimg.getWidth(), bimg.getHeight(), Image.SCALE_FAST));
    shower.getContentPane().add(new JLabel(imgIcon));
    shower.setResizable(false);
    shower.pack();
    shower.show();
    * Saves the image represented by the JavaPicture object onto disk.
    * @param newfilename the file name to save to
    * @exception java.io.IOException raised if the save fails
    public boolean saveImage(String newfilename) throws java.io.IOException
    FileOutputStream out;
    JPEGImageEncoder jpeg;
         File filen;
    try {
         filen = new File(newfilename);
         //if (filen.canWrite()){
              //return false;}
    out = new FileOutputStream(filen);
    catch (Exception e){
    System.out.println("Sorry -- that filename ("+newfilename+") isn't working");
    return false;
    try {
    jpeg = JPEGCodec.createJPEGEncoder(out);
    catch (Exception e) {
    System.out.println("Unable to create a JPEG encoder");
    return false;
    JPEGEncodeParam param = jpeg.getDefaultJPEGEncodeParam(bimg);
    param.setQuality(1.0f,true);
    jpeg.encode(bimg,param);
    out.close();
         return true;
    * Returns the pixel value of a pixel in the picture, given its coordinates.
    * @param x the x coordinate of the pixel
    * @param y the y coordinate of the pixel
    * @return the pixel value as an integer
    public int getBasicPixel(int x, int y)
    // to access pixel at row 'j' and column 'i' from the upper-left corner of
    // image.
    return bimg.getRGB(x,y);
    * Sets the value of a pixel in the picture.
    * @param x the x coordinate of the pixel
    * @param y the y coordinate of the pixel
    * @param rgb the new rgb value of the pixel
    public void setBasicPixel(int x, int y, int rgb)
    bimg.setRGB(x,y,rgb);
    * Returns a JavaPixel object representing a pixel in the picture given its coordinates
    * @param x the x coordinates of the pixel
    * @param y the y coordinates of the pixel
    * @return a JavaPixel object representing the requested pixel
    public JavaPixel getPixel(int x, int y)
    return new JavaPixel(this,x,y);
    * Test Main
    *@param String[] argvs
         public static void main(String[] args)
              JavaPicture p = new JavaPicture();
              //p.createNewImage(100,100);
              //p.showPicture();
    p.loadImage("D:\\public_html\\Apache2\\webroot\\webpage\\atlanta_skyline.jpg");
    p.showPictureWithTitle("Test");
         }

    Try this.
    import java.awt.Canvas;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.MediaTracker;
    import java.awt.Toolkit;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import com.sun.image.codec.jpeg.JPEGCodec;
    import com.sun.image.codec.jpeg.JPEGEncodeParam;
    import com.sun.image.codec.jpeg.JPEGImageEncoder;
         public class JavaPicture{
         public BufferedImage bimg;
         public JFrame shower = new JFrame();
         public ImageIcon imgIcon;
         public Canvas canvas;
         public Image image;
         Constructor
         public void JavaPicture(){
         //No picture, no values
         public int getWidth(){
         return bimg.getWidth();
         public int getHeight(){
         return bimg.getHeight();
         Load image
         public boolean loadImage(String filename){
         try{
         bimg = null;
         filename = "file://"+ filename;
         URL u = new URL(filename);
         File f = new File(u.getPath());
         bimg = ImageIO.read(f);
         Toolkit toolkit = Toolkit.getDefaultToolkit();
         image = toolkit.getImage(filename);
         MediaTracker mediaTracker = new MediaTracker(shower);
         mediaTracker.addImage(image, 0);
         try
         mediaTracker.waitForID(0);
         catch (InterruptedException ie)
         //The file did not load
         System.err.println(ie);
         bimg = new BufferedImage(image.getWidth(null), image.getHeight(null), bimg.TYPE_INT_RGB);
         Graphics g = bimg.getGraphics();
         g.drawImage(image, 0, 0, null);
         return true;
         catch (Exception e) {return false;}
         public void createNewImage(int width, int height){
         bimg = null;
         bimg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
         public void repaintImage(){
         if (shower.isVisible()){
         imgIcon.setImage(bimg.getScaledInstance(bimg.getWidth(), bimg.getHeight(), Image.SCALE_FAST));
         shower.repaint();
         public void showPictureWithTitle(String s){
         if (shower.isVisible()){
         imgIcon.setImage(bimg.getScaledInstance(bimg.getWidth(), bimg.getHeight(), Image.SCALE_FAST));
         shower.setTitle(s);
         shower.repaint();
         else {
         shower = new JFrame(s);
         imgIcon = new ImageIcon(bimg.getScaledInstance(bimg.getWidth(), bimg.getHeight(), Image.SCALE_FAST));
         shower.getContentPane().add(new JLabel(imgIcon));
         shower.setResizable(false);
         shower.pack();
         shower.show();
         Saves the image represented by the JavaPicture object onto disk.
         @param newfilename the file name to save to
         @exception java.io.IOException raised if the save fails
         public boolean saveImage(String newfilename) throws java.io.IOException
         FileOutputStream out;
         JPEGImageEncoder jpeg;
         File filen;
         try {
         filen = new File(newfilename);
         //if (filen.canWrite()){
         //return false;}
         out = new FileOutputStream(filen);
         catch (Exception e){
         System.out.println("Sorry -- that filename ("+newfilename+") isn't working");
         return false;
         try {
         jpeg = JPEGCodec.createJPEGEncoder(out);
         catch (Exception e) {
         System.out.println("Unable to create a JPEG encoder");
         return false;
         JPEGEncodeParam param = jpeg.getDefaultJPEGEncodeParam(bimg);
         param.setQuality(1.0f,true);
         jpeg.encode(bimg,param);
         out.close();
         return true;
         Returns the pixel value of a pixel in the picture, given its coordinates.
         @param x the x coordinate of the pixel
         @param y the y coordinate of the pixel
         @return the pixel value as an integer
         public int getBasicPixel(int x, int y)
         // to access pixel at row 'j' and column 'i' from the upper-left corner of
         // image.
         return bimg.getRGB(x,y);
         Sets the value of a pixel in the picture.
         @param x the x coordinate of the pixel
         @param y the y coordinate of the pixel
         @param rgb the new rgb value of the pixel
         public void setBasicPixel(int x, int y, int rgb)
         bimg.setRGB(x,y,rgb);
         Returns a JavaPixel object representing a pixel in the picture given its coordinates
         @param x the x coordinates of the pixel
         @param y the y coordinates of the pixel
         @return a JavaPixel object representing the requested pixel
         public JavaPixel getPixel(int x, int y)
         return new JavaPixel(this,x,y);
         Test Main
         @param String[] argvs
         public static void main(String[] args)
         JavaPicture p = new JavaPicture();
         //p.createNewImage(100,100);
         //p.showPicture();
         p.loadImage("D:\\public_html\\Apache2\\webroot\\webpage\\atlanta_skyline.jpg");
         p.showPictureWithTitle("Test");
         } Rasa

  • Why doesn't this program compile?

    Compiling this program:
      public class Foo<T> {
        private final Class<T> type;
        public Foo(Class<T> type) {
            this.type = type;
        public T cast(Object obj) {
            return this.type.cast(obj);
        public void handle(T obj) {
        static void apply(Foo<?> foo, Object obj) {
            foo.handle(foo.cast(obj));
      }gives this error:
        Foo.java:12: handle(capture#31 of ?) in Foo<capture#31 of ?>
          cannot be applied to (java.lang.Object)
        foo.handle(foo.cast(obj));
        ^But this seems bogus. Obviously the result of foo.cast(obj) (generic type T) should be compatible with handle(), which takes a T.
    Am I missing something or is this a compiler bug (or limitation)?
    This is on openSuSE 11.1:
        $ javac -version
        javac 1.6.0_0
        $ rpm -qf /usr/lib/jvm/java-1.6.0-openjdk/bin/javac
        java-1_6_0-openjdk-devel-1.6_b16-0.1.3Thanks for any insights.

    endasil wrote:
    alc wrote:
    Thank you, this I understand... though it's a little disappointing the compiler can't make the simple inference required. I guess that would require data flow analysis.Which is easier said than done, and sometimes impossible.
    Imagine you changed Foo thusly:
    static Foo<?> foo = new Foo<String>(String.class);
    static void apply(Object obj) {
    foo.handle(foo.cast(obj));
    }And then used it like this:
    public class GT7 {
    public static void main(String[] args) {
    new Thread(new Runnable() {
    public void run() {
    Foo.foo = new Foo<Integer>(Integer.class);
    }).start();
    Foo.apply("Hello!");
    }How's the compiler supposed to figure that one out?Yes, if there is a race condition the compiler obviously can't assume "foo" won't change. But that's not the case in the original program.. foo is a local variable. A compiler could (with sufficient work) prove this to itself. This is not one of those an impossible Turing-complete scenarios like you sometimes see with "uninitialized variable" errors where the variable actually is always initialized.
    I'm not saying that it's necessarily worth the effort to implement this in the compiler. My only point is that this was strictly a language/compiler design choice -- and a reasonable one. But there's also nothing wrong with the "intent" of the program, even if the compiler doesn't "get it".

  • Need help on this program

    Hi all,
    The purpose of this program is listed in here:
    // Inputs the miles driven and gallons used (both integers) for each tankful.
    // Calculates and displays miles per gallon obtained for each tankful and print
    // the combined miles per gallon obtained for all tankfuls up to this point.
    // All results should be floating point. Use Scanner and sentinel-controlled
    // repetition to obtain data from the user.
    // Exercise 4.17 MPG.java
    import java.util.Scanner;
    public class MPG
    private int milesDriven;
    private int gallonsUsed;
    private float result;
    public void setMilesDriven( int miles )
    milesDriven = miles;
    public void setGallonsUsed( int gallons )
    gallonsUsed = gallons;
    public String getMilesDriven( int miles )
    return milesDriven; // error occurs here
    public String getGallonsUsed( int gallons )
    return gallonsUsed;
    public MPG( float result )
    result = gallons * miles;
    System.out.printf( result);
    I try to compile this program, but the error I get is "incompatible types-found int but expected java.lang.String." How do I fix this, and how do I
    use sentinel control? If you can help me with these two things, I'd appreciate it. The sooner you can help me, the better.

    When you post code, please use[code] and [/code] tags as described in Formatting tips on the message entry page. It makes it much easier to read.
    I try to compile this program, but the error I get is
    "incompatible types-found int but expected
    java.lang.String." That means you provided an int where the program expected a string. Just like it says.
    How do I fix this,Either provide a String instead of the int, or change the code that's expecting a String to operate on an int instead.
    and how do I
    use sentinel control? II assume the instructor just wants a flag that indicates whether you're done or not. If the user enters "quit" or whatever, set that flag to true. The loop control ( while(whatever), for example) checks the flag, and either enters the loop or not.
    The sooner you can
    help me, the better.I'd advise you to keep comments like this out of your future posts. Nobody here cares about your timetable. We answer questions on our own schedule, and comments like that, and "urgent" and "asap" just annoy people.

  • Can't find (and possibly don't have) the -lglut -lGLU -lGL libraries... or at least when I try to compile a program, it returns with that error.  Any ideas (I really need to get this popgen program running on Lion)? Thx!

    Hi all,
        I'm trying to compile a population genetic software program onto my Mac Lion.  It was originally compiled to Tiger and worked beautifully.  But now I'm getting an error  'library not found for -lglut', and now I'm trying to figure out how to download the library. I've installed the command line code for Xcode, and am thinking I possibly missed installing the libraries.  I could be very wrong here... all I know is that I'm no longer near the people I would ask to help me with this so I'm asking you!  Thanks in advance for any help!  I guess my questions are: 1) where can I download the glut (potentially OpenGL) libraries (if I don't have them already)? And 2) once downloaded, how do I install it so the makefile will compile my program (in terminal, not Xcode)? Cheers,
    C

    Certain Firefox problems can be solved by performing a ''Clean reinstall''. This means you remove Firefox program files and then reinstall Firefox. Please follow these steps:
    '''Note:''' You might want to print these steps or view them in another browser.
    #Download the latest Desktop version of Firefox from http://www.mozilla.org and save the setup file to your computer.
    #After the download finishes, close all Firefox windows (click Exit from the Firefox or File menu).
    #Delete the Firefox installation folder, which is located in one of these locations, by default:
    #*'''Windows:'''
    #**C:\Program Files\Mozilla Firefox
    #**C:\Program Files (x86)\Mozilla Firefox
    #*'''Mac:''' Delete Firefox from the Applications folder.
    #*'''Linux:''' If you installed Firefox with the distro-based package manager, you should use the same way to uninstall it - see [[Installing Firefox on Linux]]. If you downloaded and installed the binary package from the [http://www.mozilla.org/firefox#desktop Firefox download page], simply remove the folder ''firefox'' in your home directory.
    #Now, go ahead and reinstall Firefox:
    ##Double-click the downloaded installation file and go through the steps of the installation wizard.
    ##Once the wizard is finished, choose to directly open Firefox after clicking the Finish button.
    Please report back to see if this helped you!

  • This program is well compiled but does not work.

    I would like to know why this program does not work properly:
    the idea is :
    1. the user introduces a text as a string
    2.the progam creates a file (with a FileOutputStream)
    3. then this file is encripted according to DES (using JCE, cipheroutputStream)
    4.the new filw is an encripte file, whose content is introduced in a string (with a FileInputStream)
    (gives no probles of compilation!!)
    (don know why it does not work)
    here goes the code:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.io.*;
    import java.security.*;
    import javax.crypto.*;
    public class cuadro extends Applet{
         private TextArea area1 =new TextArea(5,50);
         private TextArea area2 =new TextArea(5,50);
         private Button encriptar=new Button("encriptar");
         private Button decriptar=new Button("decriptar");
         public cuadro(){
              layoutApplet();
              encriptar.addActionListener(new ButtonHandler());
              decriptar.addActionListener(new ButtonHandler());
              resize(400,400);
              private void layoutApplet(){
              Panel keyPanel = new Panel();
              keyPanel.add(encriptar);
              keyPanel.add(decriptar);
              Panel textPanel = new Panel();
              Panel texto1 = new Panel();
              Panel texto2 = new Panel();
              texto1.add(new Label("               plain text"));
              texto1.add(area1);
              texto2.add(new Label("               cipher text"));
              texto2.add(area2);
              textPanel.setLayout(new GridLayout(2,1));
              textPanel.add(texto1);
              textPanel.add(texto2);
              setLayout(new BorderLayout());
              add("North", keyPanel);
              add("Center", textPanel);
              public static String encriptar(String text1){
              //generar una clave
              SecretKey clave=null;
              String text2="";
              try{
              FileOutputStream fs =new FileOutputStream ("c:/javasoft/ti.txt");
              DataOutputStream es= new DataOutputStream(fs);
                   for(int i=0;i<text1.length();++i){
                        int j=text1.charAt(i);
                        es.write(j);
                   es.close();
              }catch(IOException e){
                   System.out.println("no funciona escritura");
              }catch(SecurityException e){
                   System.out.println("el fichero existe pero es un directorio");
              try{
                   //existe archivo DESkey.ser?
                   ObjectInputStream claveFich =new ObjectInputStream(new FileInputStream ("DESKey.ser"));
                   clave = (SecretKey) claveFich.readObject();
                   claveFich.close();
              }catch(FileNotFoundException e){
                   System.out.println("creando DESkey.ser");
                   //si no, generar generar y guardar clave nueva
              try{
                   KeyGenerator claveGen = KeyGenerator.getInstance("DES");
                   clave= claveGen.generateKey();
                   ObjectOutputStream claveFich = new ObjectOutputStream(new FileOutputStream("DESKey.ser"));
                   claveFich.writeObject(clave);
                   claveFich.close();
              }catch(NoSuchAlgorithmException ex){
                   System.out.println("DES key Generator no encontrado.");
                   System.exit(0);
              }catch(IOException ex){
                   System.out.println("error al salvar la clave");
                   System.exit(0);
         }catch(Exception e){
              System.out.println("error leyendo clave");
              System.exit(0);
         //crear una cifra
         Cipher cifra = null;
         try{
              cifra= Cipher.getInstance("DES/ECB/PKCS5Padding");
              cifra.init(Cipher.ENCRYPT_MODE,clave);
         }catch(InvalidKeyException e){
              System.out.println("clave no valida");
              System.exit(0);
         }catch(Exception e){
              System.out.println("error creando cifra");
              System.exit(0);
         //leer y encriptar el archivo
         try{
              DataInputStream in = new DataInputStream(new FileInputStream("c:/javasoft/ti.txt"));
              CipherOutputStream out = new CipherOutputStream(new DataOutputStream(new FileOutputStream("c:/javasoft/t.txt")),cifra);
              int i;
              do{
                   i=in.read();
                   if(i!=-1) out.write(i);
              }while (i!=-1);
              in.close();
              out.close();
         }catch(IOException e){
              System.out.println("error en lectura y encriptacion");
              System.exit(0);
         try{
              FileInputStream fe=new FileInputStream("c:/javasoft/t.txt");
              DataInputStream le =new DataInputStream(fe);
                   int i;
                   char c;
                   do{
                        i=le.read();
                        c= (char)i;
                        if(i!=-1){
                        text2 += text2.valueOf(c);
                   }while(i!=-1);
                        le.close();
              /*}catch(FileNotFoundException e){
                   System.out.println("fichero no encontrado");
                   System.exit(0);
              }catch(ClassNotFoundException e){
                   System.out.println("clase no encontrada");
                   System.exit(0);
              */}catch(IOException e){
                   System.out.println("error e/s");
                   System.exit(0);
              return text2;
         class ButtonHandler implements ActionListener{
         public void actionPerformed(ActionEvent e){
              try{
              if (e.getActionCommand().equals(encriptar.getLabel()))
                   //     area2.setText(t1)
                   area2.setText(encriptar(area1.getText()));
                   //area2.setText("escribe algo");
                   else if (e.getActionCommand().equals(decriptar.getLabel()))
                        System.out.println("esto es decriptar");
                        //area2.setText("hola");
         }catch(Exception ex){
              System.out.println("error en motor de encriptacion");
                   //else System.out.println("no coge el boton encriptado/decript");

    If you don't require your code to run as an applet, you will probably get more mileage from refactoring it to run as an application.
    As sudha_mp implied, an unsigned applet will fail on the line
    FileInputStream fe=new FileInputStream("c:/javasoft/t.txt");
    due to security restrictions. (Which, incidentally, are there for a very good reason)

  • How come this program compiles?

    class Base
         Base()
              int i = 100;
              System.out.println(i);
    public class Pri extends Base
         static int i = 200;
         public static void main(String[] args)
              System.out.println(i);
              Pri p = new Pri();
    i get very confused here. in the main, the value of "i" will be printed to the standard output even before the class Pri is instantiated! how come this program can compile?
    your help will be very much appreciated.
    eileen2

    This is because your class Pri extends Base. Because you didn't specify any class Pri constructor, java automatilcally created a no-argument constructor of class Pri with a call to the superclass constructor Base(). You can validate this by adding another Base constructor with arguments and then removing the no-argument Base constructor. Pri() will not compile.

  • My daughter is a college student. she needs to write and compile c programs on her mac for a class this semester. what is the best place for her to start to get the correct compiler etc. to use ? thanks

    my daughter is a college student. she needs to write and compile c programs on her mac for a class this semester. what is the best place for her to start to get the correct compiler etc. to use ? thanks

    If you know that you will not be asked to design GUI interfaces, and the C programming course will adhere to command line compilation environments, then get the Xcode command-line developer tools, and skip the extra complication of Xcode until you absolutely need it. Apple has kicked GNU C to the curb and is rightly so, using Clang/LLVM compiler technology.
    Sign up for a free Apple Developer account using your Apple ID, and then visit the Mac Dev Center, and towards the bottom of the page, you will see additional downloads. Click on the associated, all down loads link. Know your OS X version beforehand, as the command-line tool releases are tied to general operating system versions, and the most recent Xcode version.  That said, there are currently two March 9, 2015 command-line tools for Xcode 6.2 — one for OS X 10.9 Mavericks, and the other for OS X Yosemite.

  • Can someone else try to compile this and see why the program is returning..

    Can someone else try to compile this and see why the program is returning "false" when I try to delete the files on exit (at bottom of code)... I have the source code uploaded to the web as well as my 2 text test files inside a zip file(they need to be unzipped so you can try to test the program) and .class file... the program works the way i want it to, but i just can't seem to delete the 3 temporary files i use... why??? why does it return false???
    Thanks in advance,
    Disco Hristo
    http://www.holytrinity-holycross.org/DiscoHristo/Assemble.java
    http://www.holytrinity-holycross.org/DiscoHristo/Assemble.class
    http://www.holytrinity-holycross.org/DiscoHristo/tests.zip
    * Assemble.java 1.0 02/06/22
    * @author Disco Hristo
    * @version 1.0
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    public class Assemble
         public static void main(String args[]) throws IOException
              if (args.length > 0) //     Checks to see if there are any arguments
                   printArgumentInfo ();
              else // if no arguments run the program
                   getInput ();
                   printToFile ();
                   deleteFiles ();
         public static void getInput () throws IOException
         //     Gets the input and then send it to 3 files according to Tags
              File head = new File ("head.chris");
    PrintStream headStream = new PrintStream (new FileOutputStream (head));
    File body = new File ("body.chris");
    PrintStream bodyStream = new PrintStream (new FileOutputStream (body));
    File foot = new File ("foot.chris");
    PrintStream footStream = new PrintStream (new FileOutputStream (foot));
    String input; //     String used to store input                
    File d = new File(".");
    String files[] = d.list();
    for (int n=0; n!=files.length; n++)
         if (files[n].endsWith(".txt") == true)
              String fileName = files[n];
              BufferedReader in = new BufferedReader (new FileReader(fileName));
                   while (true)
                   input = in.readLine();
                   if (input != null)
                        input = input.trim();
                        if (input == null) // if no more input                          
                             break;
                        else if ( (input.compareTo("<HEAD>")) == 0) // if start of <HEAD> text
                             do
                                  input = in.readLine();
                                       if (input != null)
                                       input = input.trim();
                                       if ( ((input.compareTo("<BODY>")) == 0) ||
                                                      ((input.compareTo("<FOOT>")) == 0) ||
                                                      ((input.compareTo("</BODY>")) == 0) ||
                                                      ((input.compareTo("</FOOT>")) == 0) ||
                                                      ((input.compareTo("<HEAD>")) == 0))
                                                      //checks to see if tags in input are in correct order
                                            System.out.println("Input Is Incorrectly Formatted - Tag Error");
                                            System.out.println("Close your <HEAD> tag before starting another tag.");
                                            System.exit(1); //exit program without printing data                                                   
                                       if ( (input.compareTo("</HEAD>")) != 0) //if not end of tag
                                            headStream.println(input); //print to text file
                             while ( (input.compareTo("</HEAD>")) != 0);
                        else if ( (input.compareTo("<BODY>")) == 0) // if start of <BODY> text
                             do
                                  input = in.readLine();
                                  if (input != null)
                                       input = input.trim();
                                       if ( ((input.compareTo("<HEAD>")) == 0) ||
                                                      ((input.compareTo("<FOOT>")) == 0) ||
                                                      ((input.compareTo("</HEAD>")) == 0) ||
                                                      ((input.compareTo("</FOOT>")) == 0) ||
                                                      ((input.compareTo("<BODY>")) == 0))
                                                      //checks to see if tags in input are in correct order
                                            System.out.println("Input Is Incorrectly Formatted - Tag Error");
                                            System.out.println("Close your <BODY> tag before starting another tag.");
                                            System.exit(1); //exit program without printing data                                                   
                                       if ( (input.compareTo("</BODY>")) != 0) //if not end of tag
                                            bodyStream.println(input); //print to text file
                             while ( (input.compareTo("</BODY>")) != 0);
                             else if ( (input.compareTo("<FOOT>")) == 0) // if start of <FOOT> text
                                  do
                                  input = in.readLine();
                                  if (input != null)
                                       input = input.trim();
                                       if ( ((input.compareTo("<BODY>")) == 0) ||
                                            ((input.compareTo("<HEAD>")) == 0) ||
                                                 ((input.compareTo("</BODY>")) == 0) ||
                                                 ((input.compareTo("</HEAD>")) == 0) ||
                                                 ((input.compareTo("<FOOT>")) == 0))
                                                 //checks to see if tags in input are in correct order
                                            System.out.println("Input Is Incorrectly Formatted - Tag Error");
                                            System.out.println("Close your <FOOT> tag before starting another tag.");
                                            System.exit(1); //exit program without printing data                                                   
                                       if ( (input.compareTo("</FOOT>")) != 0) //if not end of tag
                                                 footStream.println(input); //print to text file
                             while ( (input.compareTo("</FOOT>")) != 0);
                   else
                        break;
    public static void printToFile () throws IOException
    // Prints the text from head.txt, body.txt, and foot.txt to the output.log
         File head = new File ("head.chris");
         FileReader headReader = new FileReader(head);
              BufferedReader inHead = new BufferedReader(headReader);
              File body = new File ("body.chris");
              FileReader bodyReader = new FileReader(body);
              BufferedReader inBody = new BufferedReader(bodyReader);
              File foot = new File ("foot.chris");
              FileReader footReader = new FileReader(foot);
              BufferedReader inFoot = new BufferedReader(footReader);
              PrintStream outputStream = new PrintStream (new FileOutputStream (new File("output.log")));
              String output;     //string used to store output
              while (true)
                   output = inHead.readLine();
                   if (output == null) //if no more text to get from file
                   break;
                   else
                        outputStream.println(output); // print to output.log
              while (true)
                   output = inBody.readLine();
                   if (output == null)// if no more text to get from file
                   break;
                   else
                        outputStream.println(output); // print to output.log
              while (true)
                   output = inFoot.readLine();
                   if (output == null) //if no more text to get from file
                   break;
                   else
                        outputStream.println(output); // print to output.log
              //Close up the files
              inHead.close ();
              inBody.close ();
              inFoot.close ();
              outputStream.close ();     
         public static void printArgumentInfo () //     Prints argument info to screen
              System.out.println("");
              System.out.println("Disco Hristo");
              System.out.println("");
              System.out.println("Assemble.class is a small program that");
              System.out.println("takes in as input a body of text and then");
              System.out.println("outputs the text in an order according to");
              System.out.println("the tags that are placed in the input.");
         public static void deleteFiles ()
              File deleteHead = new File ("head.chris");
              File deleteBody = new File ("body.chris");
              File deleteFoot = new File ("foot.chris");
              deleteHead.deleteOnExit();
              deleteBody.deleteOnExit();
              deleteFoot.deleteOnExit();
    }

    I tired your program, it still gives false for files deleted. I tool the same functions you used in your program and ran it. The files get deleted. Tried this :
    <pre>
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    public class FileTest {
         public static void main(String args[]) {
              FileTest f = new FileTest();
              try {
                   f.createFile();
                   f.deleteFile();
              } catch(IOException ioe){
                   System.out.println(ioe.getMessage());
         public void createFile() throws IOException {
              System.out.println("In create file method...");
              File test = new File("test1.txt");
              File tst = new File("text2.txt");
              PrintStream testStream = new PrintStream (new FileOutputStream (test));
              PrintStream tstStream = new PrintStream (new FileOutputStream (tst));
              testStream.println("this is a test to delete a file");
              tstStream.println("this is the second file created");
              testStream.close();
              tstStream.close();          
         public void deleteFile() throws IOException {
              File test = new File("test1.txt");
              File tst = new File("text2.txt");
              System.out.println(test.delete());
              System.out.println(tst.delete());
    </pre>
    Also check the starting and closing braces for your if..else blocks.
    -Siva

  • Having trouble compiling this file reader program!!

    Hi,
    I wrote this program to read a flat file so I can parse it thereafter. I'm not sure where I need to change syntax.
    If need be, I can send the error msg.
    Thanks in advance!!
    import java.io.*;
    class FileReader1
         public String readLine() throws IOException
              try {
                   //FileReader br = new FileReader(new
                   //File("C:\\Shared CLM\\netsvc.txt")) ;
                   LineNumberReader lnr = new LineNumberReader(new FileReader(
                   "C:\\Shared CLM\\netsvc.txt")) ;
                   String line = lnr.readLine() ;
                   //switch() {...}
                        lnr.close() ;
                        //br.close() ;
                   } catch (IOException e) {
                                  e.printStackTrace();
    }

    Well, I removed the ";" but I am still getting 9 errors...
    C:\mail\CLM Mail Program\Ballb.java:6: ';' expected
         public String readLine() throws IOException
    ^
    C:\mail\CLM Mail Program\Ballb.java:6: missing method body, or declare abstract
         public String readLine() throws IOException
    ^
    .\FileReader.java:7: ';' expected
    public String readLine() throws IOException
    ^
    .\FileReader.java:28: '}' expected
    ^
    .\FileReader.java:7: cannot resolve symbol
    symbol : class IOException
    location: class FileReader
    public String readLine() throws IOException
    ^
    C:\mail\CLM Mail Program\Ballb.java:13: cannot resolve symbol
    symbol : constructor FileReader (java.lang.String)
    location: class FileReader
              {LineNumberReader lnr = new LineNumberReader(new FileReader("C:\\Shared CLM\\netsvc.txt")) ;
                                                                 ^
    C:\mail\CLM Mail Program\Ballb.java:14: cannot resolve symbol
    symbol  : variable line 
    location: class Ballb
              line = lnr.readLine() ;
                    ^
    C:\mail\CLM Mail Program\Ballb.java:21: return outside method
                   return line;
                            ^
    .\FileReader.java:7: missing method body, or declare abstract
    public String readLine() throws IOException
                  ^
    9 errors                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • [SOLVED]Compiling a program from source (Tomoe)

    I'm trying to compile Tomoe: http://tomoe.sourceforge.jp/cgi-bin/en/blog/index.rb
    It is a handwriting recognition tool for East Asian languages. For those of you familiar with them, you'd know that there are some characters that are just so obscure you can't type them with your IME and the only way to input them is with a handwriting recognition program. (Browsing a unicode character map is only something a madman can do) MS has one built in their IME, but I've had to live by copying things from wiktionary up until now on Linux, and I think this program might be my saving grace if I can get it working.
    I would want to make a PKGBUILD, but I really have no experiance with that kind of stuff at all, so I'm going to try to compile it from source the old fashioned way at least. I figured if it installs things into /usr/local/ by default it won't mess up with pacman too much.
    However I'd need 3 packages. One for tomoe, another for tomoe-gtk, and another for scim-tomoe. And the 3rd depends on the 2nd which depends on the 1st. I installed tomoe fine with ./configure && make && make install, but when I try to install tomoe-gtk I get an error at ./configure:
    checking for TOMOE... configure: error: Package requirements (tomoe >= 0.4.0) were not met:
    No package 'tomoe' found
    Consider adjusting the PKG_CONFIG_PATH environment variable if you
    installed software in a non-standard prefix.
    Alternatively, you may set the environment variables TOMOE_CFLAGS
    and TOMOE_LIBS to avoid the need to call pkg-config.
    See the pkg-config man page for more details.
    Of course I know that I installed tomoe, slocate gives me:
    (It gave me more stuff too, but they are all in the build directory in my home so I excluded them.)
    /usr/local/etc/tomoe
    /usr/local/etc/tomoe/config
    /usr/local/include/tomoe
    /usr/local/include/tomoe/pytomoe-utils.h
    /usr/local/include/tomoe/tomoe-candidate.h
    /usr/local/include/tomoe/tomoe-char.h
    /usr/local/include/tomoe/tomoe-config.h
    /usr/local/include/tomoe/tomoe-context.h
    /usr/local/include/tomoe/tomoe-dict.h
    /usr/local/include/tomoe/tomoe-enum-types.h
    /usr/local/include/tomoe/tomoe-module-impl.h
    /usr/local/include/tomoe/tomoe-module.h
    /usr/local/include/tomoe/tomoe-query.h
    /usr/local/include/tomoe/tomoe-reading.h
    /usr/local/include/tomoe/tomoe-recognizer.h
    /usr/local/include/tomoe/tomoe-shelf.h
    /usr/local/include/tomoe/tomoe-writing.h
    /usr/local/include/tomoe/tomoe.h
    /usr/local/lib/libtomoe.a
    /usr/local/lib/libtomoe.la
    /usr/local/lib/libtomoe.so
    /usr/local/lib/libtomoe.so.0
    /usr/local/lib/libtomoe.so.0.1.0
    /usr/local/lib/tomoe
    /usr/local/lib/pkgconfig/pytomoe.pc
    /usr/local/lib/pkgconfig/tomoe.pc
    /usr/local/lib/python2.6/site-packages/tomoe.a
    /usr/local/lib/python2.6/site-packages/tomoe.la
    /usr/local/lib/python2.6/site-packages/tomoe.so
    /usr/local/lib/tomoe/module
    /usr/local/lib/tomoe/module/dict
    /usr/local/lib/tomoe/module/recognizer
    /usr/local/lib/tomoe/module/dict/mysql.a
    /usr/local/lib/tomoe/module/dict/mysql.la
    /usr/local/lib/tomoe/module/dict/mysql.so
    /usr/local/lib/tomoe/module/dict/unihan.a
    /usr/local/lib/tomoe/module/dict/unihan.la
    /usr/local/lib/tomoe/module/dict/unihan.so
    /usr/local/lib/tomoe/module/dict/xml.a
    /usr/local/lib/tomoe/module/dict/xml.la
    /usr/local/lib/tomoe/module/dict/xml.so
    /usr/local/lib/tomoe/module/recognizer/simple.a
    /usr/local/lib/tomoe/module/recognizer/simple.la
    /usr/local/lib/tomoe/module/recognizer/simple.so
    /usr/local/share/tomoe
    /usr/local/share/gtk-doc/html/tomoe
    /usr/local/share/gtk-doc/html/tomoe/TomoeCandidate.html
    /usr/local/share/gtk-doc/html/tomoe/TomoeChar.html
    /usr/local/share/gtk-doc/html/tomoe/TomoeConfig.html
    /usr/local/share/gtk-doc/html/tomoe/TomoeContext.html
    /usr/local/share/gtk-doc/html/tomoe/TomoeDict.html
    /usr/local/share/gtk-doc/html/tomoe/TomoeQuery.html
    /usr/local/share/gtk-doc/html/tomoe/TomoeReading.html
    /usr/local/share/gtk-doc/html/tomoe/TomoeRecognizer.html
    /usr/local/share/gtk-doc/html/tomoe/TomoeShelf.html
    /usr/local/share/gtk-doc/html/tomoe/TomoeWriting.html
    /usr/local/share/gtk-doc/html/tomoe/home.png
    /usr/local/share/gtk-doc/html/tomoe/index.html
    /usr/local/share/gtk-doc/html/tomoe/index.sgml
    /usr/local/share/gtk-doc/html/tomoe/ix01.html
    /usr/local/share/gtk-doc/html/tomoe/left.png
    /usr/local/share/gtk-doc/html/tomoe/right.png
    /usr/local/share/gtk-doc/html/tomoe/style.css
    /usr/local/share/gtk-doc/html/tomoe/tomoe-tomoe.html
    /usr/local/share/gtk-doc/html/tomoe/tomoe.devhelp
    /usr/local/share/gtk-doc/html/tomoe/tomoe.devhelp2
    /usr/local/share/gtk-doc/html/tomoe/tomoe.html
    /usr/local/share/gtk-doc/html/tomoe/up.png
    /usr/local/share/locale/ja/LC_MESSAGES/tomoe.mo
    /usr/local/share/tomoe/dict
    /usr/local/share/tomoe/dict.dtd
    /usr/local/share/tomoe/python
    /usr/local/share/tomoe/recognizer
    /usr/local/share/tomoe/xml2est.rb
    /usr/local/share/tomoe/python/tomoe.defs
    /usr/local/share/tomoe/recognizer/handwriting-ja.xml
    /usr/local/share/tomoe/recognizer/handwriting-zh_CN.xml
    I've tried:
    export PKG_CONFIG_PATH=/usr/local/lib/tomoe:$PKG_CONFIG_PATH
    export PKG_CONFIG_PATH=/usr/local/lib:$PKG_CONFIG_PATH
    And neither of those seemed to work so I then set TOMOE_CFLAGS and TOMOE_LIBS and it indeed avoided the need to call pkg-config and the configure script went on, but I got the same problem for gucharmap, which I tried installing with pacman and then starting a new session, but it still didn't work so I had to set the environment variables to skip it and then the configure script finished, but make not so surprisingly failed.
    So what should I do to get this to compile?
    Last edited by sokuban (2008-11-24 02:48:46)

    Zoulnix wrote:
    Hello there, sokuban... just wanted to tell you that i have uploaded
    scim-tomoe, tomoe, tomoe-gtk and uim-tomoe-gtk PKGBUILD's to the AUR.
    ... would be good if someone could test  the pkgbuilds
    out to see so everything works as it should.
    tomoe-gtk had to be compiled without gucharmap. from what i could see the tomoe-gtk is not compatible with the latest version of gucharmap...
    Thanks! The tomoe packages installs and works perfectly.
    But now I've got another little problem. For some strange reason they decided that it would only load a dictionary when the locale is set to Chinese or Japanese. My computer currently runs on a ms_MY.utf-8 locale and while I wouldn't really mind putting it to ja_JP.utf-8 I'd prefer it if there is a way I can make it so that tomoe is always run with a Japanese locale no matter what locale the rest of my system is because I often randomly change it.
    While I can directly run:
    $ LANG=ja_JP.UTF-8 scim-tomoe
    from a terminal and the dictionaries are loaded fine, I'd end up only being able to write in the terminal itself which is pretty useless. Right clicking on the scim icon and selecting handwriting recognition will give me the ms_MY version which doesn't have any dictionaries loaded.
    Anyone know a way to do it?
    EDIT: So I tried setting my whole locale to Japanese. Only problem is, Thunar has a bug with Japanese. Maybe its because the Japanese name for filesystem is too long, but the sidebar is stuck out too much and cannot be pushed in. Also since it is so long my filesystem icon on my desktop can't display its whole name, I wouldn't really call that a bug, but it isn't pretty to look at.
    And I just noticed but xfce terminal fonts are messed up too. I'm too lazy to fix all this so I'm going back to English now. It would probbably be much easier to find a way to always run only this program with a Japanese locale than fix all the problems I'm getting with the whole system in a Japanese locale.
    EDIT2: Solved by running scim itself in ja_JP.UTF-8 (why didn't I think of this earlier?).
    Last edited by sokuban (2008-11-24 02:49:24)

  • Java newbie (what's could be wrong with this program?)

    First things first, I just started programming with JAVA recently so please forgive me if it seems stupid. Since I am so relatively new to the language, in order to get a feel for it I started running some simple scripts. I can compile and execute most of them without any problem. However when I tried to compile this one I get a couple of errors I am not familiar with. So my question is what could be wrong and what needs to be changed in order to get it to work? or if the syntax is correct could there be some other problem?
    On a side note, I am coming more from a C and C++ background so if anyone can recommend a way to start learning the JAVA language from a prespective in C that would be highly appreciated.
    System Environment: I am using j2sdk1.4.2 on a Windows 2000 machine running SP3.
    If anything else needs further clarification please let me know.
    |------------------------- The Code -----------------------------------|
    package RockPaperScissors;
    import java.util.HashMap;
    public class RockPaperScissors {
    String[] weapons = {"Rock", "Paper", "Scissors"};
    EasyIn easy = new EasyIn();
    HashMap winners = new HashMap();
    String playerWeapon;
    String cpuWeapon;
    int cpuScore = 0;
    int playerScore = 0;
    public static void main(String[] args) {
    RockPaperScissors rps = new RockPaperScissors();
    boolean quit = false;
    while (quit == false) {
    rps.playerWeapon = rps.getPlayerWeapon();
    rps.cpuWeapon = rps.getCpuWeapon();
    System.out.println("\nYou chose: " + rps.playerWeapon);
    System.out.println("The computer chose: " + rps.cpuWeapon + "\n");
    rps.getWinner(rps.cpuWeapon, rps.playerWeapon);
    if (rps.playAgain() == false) {
    quit = true;
    System.out.println("Bye!");
    public RockPaperScissors() {
    String rock = "Rock";
    String paper = "Paper";
    String scissors = "Scissors";
    winners.put(rock, scissors);
    winners.put(scissors, paper);
    winners.put(paper, rock);
    System.out.println("\n\t\tWelcome to Rock-Paper-Scissors!\n");
    public String getPlayerWeapon() {
    int choice = 6;
    String weapon = null;
    System.out.println("\nPlease Choose your Weapon: \n");
    System.out.println("1. Rock \n2. Paper \n3. Scissors \n\n0. Quit");
    try {
    choice = easy.readInt();
    } catch (Exception e) {
    errorMsg();
    return getPlayerWeapon();
    if (choice == 0) {
    System.out.println("Quitting...");
    System.exit(0);
    } else {
    try {
    weapon = weapons[(choice - 1)];
    } catch (IndexOutOfBoundsException e) {
    errorMsg();
    return getPlayerWeapon();
    return weapon;
    public void errorMsg() {
    System.out.println("\nInvalid Entry.");
    System.out.println("Please Select Again...\n\n");
    public String getCpuWeapon() {
    int rounded = -1;
    while (rounded < 0 || rounded > 2) {
    double randomNum = Math.random();
    rounded = Math.round(3 * (float)(randomNum));
    return weapons[rounded];
    public void getWinner(String cpuWeapon, String playerWeapon) {
    if (cpuWeapon == playerWeapon) {
    System.out.println("Tie!\n");
    } else if (winners.get(cpuWeapon) == playerWeapon) {
    System.out.println("Computer Wins!\n");
    cpuScore++;
    } else if (winners.get(playerWeapon) == cpuWeapon) {
    System.out.println("You Win!\n");
    playerScore++;
    public boolean playAgain() {
    printScore();
    System.out.print("\nPlay Again (y/n)? ");
    char answer = easy.readChar();
    while (true) {
    if (Character.toUpperCase(answer) == 'Y') {
    return true;
    } else if (Character.toUpperCase(answer) == 'N') {
    return false;
    } else {
    errorMsg();
    return playAgain();
    public void printScore() {
    System.out.println("Current Score:");
    System.out.println("Player: " + playerScore);
    System.out.println("Computer: " + cpuScore);
    |------------------------- Compiler Output ----------------------------|
    C:\ide-xxxname\sampledir\RockPaperScissors>javac RockPaperScissors.java
    RockPaperScissors.java:8: cannot resolve symbol
    symbol : class EasyIn
    location: class RockPaperScissors
    EasyIn easy = new EasyIn();
    ^
    RockPaperScissors.java:8: cannot resolve symbol
    symbol : class EasyIn
    location: class RockPaperScissors
    EasyIn easy = new EasyIn();
    ^
    2 errors

    limeybrit9,
    This importing certainly seems to be the problem, I'm still not used to how compilation works within the JAVA language, I'll play around with it a bit and see if I can get it to work correctly.
    bschauwe,
    The C++ approach has certainly clarified some of the points. I guess I will be sticking to that.
    bsampieri,
    You were correct on the class looking rather generic, but as I mentioned before I was just sort of tinkering to see if I could get it to work.
    Thanks to all for the help, very much appreciated.

  • New to Java and need help with this program..please!

    I'd really appreciate any helpful comments about this program assignment that I have to turn in a week from Friday. I'm taking a class one night a week and completely new to Java. I'd ask my professor for help, but we can't call him during the week and he never answers e-mails. He didn't tell us how to call from other classes yet, and I just can't get the darn thing to do what I want it to do!
    The assignment requirements are:
    1. Change a card game application that draws two cards
    and the higher card wins, to a Blackjack application
    2. Include a new class called Hand
    3. The Hand class should record the number of draws
    4. The application should prompt for a number of draws
    5. The game is played against the Dealer
    6. The dealer always draws a card if the dealer's hand total is <= 17
    7. Prompt the player after each hand if he wants to quit
    8. Display the total games won by the dealer and total and the total games wond by the player after each hand
    9. Display all of the dealer's and player's cards at the
    end of each hand
    10. Player has the option of drawing an additional card after the first two cards
    11. The Ace can have a value of 11 or 1
    (Even though it's not called for in the requirements, I would like to be able to let the Ace have a value of 1 or an 11)
    The following is my code with some comments about a few things that are driving me nuts:
    import java.util.*;
    import javax.swing.*;
    import java.text.*;
    public class CardDeck
    public CardDeck()
    deck = new Card[52];
    fill();
    shuffle();
    public void fill()
    int i;
    int j;
    for (i = 1; i <= 13; i++)
    for (j = 1; j <= 4; j++)
    deck[4 * (i - 1) + j - 1] = new Card(i, j);
    cards = 52;
    public void shuffle()
    int next;
    for (next = 0; next < cards - 1; next++)
    int rand = (int)(Math.random()*(next+1));
    Card temp = deck[next];
    deck[next] = deck[rand];
    deck[rand] = temp;
    public final Card draw()
    if (cards == 0)
    return null;
    cards--;
    return deck[cards];
    public int changeValue()
    int val = 0;
    boolean ace = false;
    int cds;
    for (int i = 0; i < cards; i++)
    if (cardValue > 10)
    cardValue = 10;
    if (cardValue ==1)     {
    ace = true;
    val = val + cardValue;
    if ( ace = true && val + 10 <= 21 )
    val = val + 10;
    return val;
    public static void main(String[] args)
    CardDeck d = new CardDeck();
    int x = 3;
    int i;
    int wins = 1;
    int playerTotal = 1;
    do {
    Card dealer = (d.draw());
    /**I've tried everything I can think of to call the ChangeValue() method after I draw the card, but nothing is working for me.**/
    System.out.println("Dealer draws: " + dealer);
    do {
    dealer = (d.draw());
    System.out.println(" " + dealer);
    }while (dealer.rank() <= 17);
    Card mine = d.draw();
    System.out.println("\t\t\t\t Player draws: "
    + mine);
    mine = d.draw();
    System.out.println("\t\t\t\t\t\t" + mine);
    do{
    String input = JOptionPane.showInputDialog
    ("Would you like a card? ");
    if(input.equalsIgnoreCase("yes"))
         mine = d.draw();
    System.out.println("\t\t\t\t\t\t" + mine);
         playerTotal++;
         else if(input.equalsIgnoreCase("no"))
    System.out.println("\t\t\t\t Player stands");
         else
    System.out.println("\t\tInvalid input.
    Please try again.");
    I don't know how to go about making and calling a method or class that will combine the total cards delt to the player and the total cards delt to the dealer. The rank() method only seems to give me the last cards drawn to compare with when I try to do the tests.**/
    if ((dealer.rank() > mine.rank())
    && (dealer.rank() <= 21)
    || (mine.rank() > 21)
    && (dealer.rank() < 22)
    || ((dealer.rank() == 21)
    && (mine.rank() == 21))
    || ((mine.rank() > 21)
    && (dealer.rank() <= 21)))
    System.out.println("Dealer wins");
    wins++;
         else
    System.out.println("I win!");
    break;
    } while (playerTotal <= 1);
    String stop = JOptionPane.showInputDialog
    ("Would you like to play again? ");
    if (stop.equalsIgnoreCase("no"))
    break;
    if (rounds == 5)
    System.out.println("Player wins " +
    (CardDeck.rounds - wins) + "rounds");
    } while (rounds <= 5);
    private Card[] deck;
    private int cards;
    public static int rounds = 1;
    public int cardValue;
    /**When I try to compile this nested class, I get an error message saying I need a brace here and at the end of the program. I don't know if any of this code would work because I've tried adding braces and still can't compile it.**/
    class Hand()
    static int r = 1;
    public Hand() { CardDeck.rounds = r; }
    public int getRounds() { return r++; }
    final class Card
    public static final int ACE = 1;
    public static final int JACK = 11;
    public static final int QUEEN = 12;
    public static final int KING = 13;
    public static final int CLUBS = 1;
    public static final int DIAMONDS = 2;
    public static final int HEARTS = 3;
    public static final int SPADES = 4;
    public Card(int v, int s)
    value = v;
    suit = s;
    public int getValue() { return value; }
    public int getSuit() { return suit;  }
    public int rank()
    if (value == 1)
    return 4 * 13 + suit;
    else
    return 4 * (value - 1) + suit;
    /**This works, but I'm confused. How is this method called? Does it call itself?**/
    public String toString()
    String v;
    String s;
    if (value == ACE)
    v = "Ace";
    else if (value == JACK)
    v = "Jack";
    else if (value == QUEEN)
    v = "Queen";
    else if (value == KING)
    v = "King";
    else
    v = String.valueOf(value);
    if (suit == DIAMONDS)
    s = "Diamonds";
    else if (suit == HEARTS)
    s = "Hearts";
    else if (suit == SPADES)
    s = "Spades";
    else
    s = "Clubs";
    return v + " of " + s;
    private int value; //Value is an integer, so how can a
    private int suit; //string be assigned to an integer?
    }

    Thank you so much for offering to help me with this Jamie! When I tried to call change value using:
    Card dealer = (d.changeValue());
    I get an error message saying:
    Incompatible types found: int
    required: Card
    I had my weekly class last night and the professor cleared up a few things for me, but I've not had time to make all of the necessary changes. I did find out how toString worked, so that's one question out of the way, and he gave us a lot of information for adding another class to generate random numbers.
    Again, thank you so much. I really want to learn this but I'm feeling so stupid right now. Any help you can give me about the above error message would be appreciated.

Maybe you are looking for

  • How to load JMF player in web without applet

    Is it possible to load JMF player in html or php page without the help of applet or jsp or jsf? I heared that flash can be handy for this purpose as java can be loaded in flash movie, can anyone give me better idea about this?

  • Can I use my Nikon D90 AVI files in Premiere Pro CC on my iMac?

    Hi and thanks in advance to anyone who can lend me a hand. I am new to both Premiere Pro CC and Macs. I have used my Nikon D90 AVI files before with Premiere Elements on my PC with no problem, but the same films aren't working on my new setup with Pr

  • Installing Coldfusion 9 and Apache 2.2 on Windows Server 2008 R2 Standard

    I'm having issues getting ColdFusion 9 working with Apache 2.2 on Windows Server 2008 R2 Standard. The server is brand new and it's a fresh install of Apache and ColdFusion 9. Having installed Apache, I tested the web server and it was working fine,

  • Using 5800 with universal iTrip

    Hello, I have a Griffin iTrip auto universal with the standard 3.5mm jack. If I connect this directly into the 5800 I get the option of choosing from headphone, lineout,etc,etc. If I choose either headphone or lineout, i get a really high strong and

  • Adobe Reader XI not working for me (Windows 7)

    I just installed adobe reader XI and now I can't open any PDF files. The application itself won't even start properly. The default window opens but then it completely shutsdown without any indication of why it did so. No error report or anything.