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 3 of 3

Thread: program doesn't woerk

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

    Default program doesn't woerk

    package kmiskaiciuoklis;

    import java.awt.BorderLayout;
    import javax.swing.JFrame;
    //kmiGUI.java turinys
    import java.awt.FlowLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JButton;
    import javax.swing.JTextField;
    import javax.swing.JOptionPane;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;


    interface Interfeisas {
    public JLabel item1 = null;
    public JLabel item2 = null;
    public JTextField mase = null;
    public JTextField ugis = null;
    public JButton mygtukas = null;
    }

    public class Main extends JFrame implements Interfeisas {

    private JLabel item1;
    private JLabel item2;
    private JTextField mase;
    private JTextField ugis;
    private JButton mygtukas;

    public float indeksas;

    public Main () {
    super("KMI skaiciuokle");

    setLayout(new FlowLayout());

    item1 = new JLabel("Mase: ");
    item1.setToolTipText("Iveskite zmogaus mase kilogramais");
    add(item1);

    mase = new JTextField(10);
    mase.setToolTipText("Iveskite zmogaus mase kilogramais");
    add(mase);

    item2 = new JLabel("Ugis: ");
    item2.setToolTipText("Iveskite zmogaus ugi centimetrais");
    add(item2);

    ugis = new JTextField(10);
    ugis.setToolTipText("Iveskite zmogaus ugi centimetrais");
    add(ugis);

    mygtukas = new JButton("Skaiciuoti");
    add(mygtukas);

    HandlerClass handler = new HandlerClass();
    mygtukas.addActionListener(handler);

    ImageIcon image = new ImageIcon("zmogeliukas.jpg");
    //image.setLayout(new BorderLayout());
    //JPanel.add(image, BorderLayout.SOUTH);
    }

    void storulis () {
    if (indeksas > 25)
    JOptionPane.showMessageDialog (null,"tu storas");
    }
    void skeletas (){
    if (indeksas < 18)
    JOptionPane.showMessageDialog(null,"per kudas,eik pavalgyk");
    }
    void normalus (){
    if (indeksas >18 && indeksas <25)
    JOptionPane.showMessageDialog(null,"esi normalus");
    }


    private class HandlerClass implements ActionListener {
    public void actionPerformed (ActionEvent event) {
    if (event.getSource() == mygtukas) {
    try {
    float u = Float.parseFloat(ugis.getText()), m = Float.parseFloat(mase.getText());
    indeksas = (float)Math.round(m/(u*u/10000)*1000)/1000;
    JOptionPane.showMessageDialog(null, "Kuno mases indeksas yra "+indeksas,"Apskaiciuotas KMI",JOptionPane.INFORMATION_MESSAGE);

    }
    catch (NumberFormatException e) {
    System.out.println("error");
    }
    }


    }


    }

    }
    package kmiskaiciuoklis;

    import java.util.*;


    import javax.swing.JFrame;

    public class kmi extends Main{

    public static void main (String args[]) {
    Thread t1 = new Thread(new thread("pirmas"));
    Thread t2 = new Thread(new thread("antras"));
    Thread t3 = new Thread(new thread("trecias"));

    t1.start();
    t2.start();
    t3.start();

    Main xObj = new Main();
    xObj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
    xObj.setSize(205,180);
    xObj.setVisible(true);
    }

    }

    package kmiskaiciuoklis;
    import java.util.*;
    /**
    *
    * @author home
    */
    public class thread implements Runnable {
    String vardas;
    int sk;
    Random r = new Random();
    public thread(String x){
    vardas = x;
    sk = r.nextInt(999);
    }


    public void run(){
    try{
    System.out.printf("%s kmi yra %d\n", vardas, sk);
    Thread.sleep(sk);
    System.out.printf("%s suskaiciuota \n", vardas);
    }catch(Exception e){}

    }}
    something is wrong with my program and also I don't know where to use treads and how to do it, actually that should be done by my friend, but it's time to give it for teacher and she still didn't do anything, so i had to do all the work
    Last edited by shushu; May 14th, 2012 at 01:35 PM.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,699
    Thanks
    25
    Thanked 334 Times in 310 Posts

    Default Re: program doesn't woerk

    Please wrap your code in tags.

    What is wrong with your code?
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: program doesn't woerk

    You can't initialize inside an interface.

    Also, your interface right now appears to not be doing much, if anything, as you have those same variables with types and names exactly the same inside that constructor and that's what you're initializing in that one, not the ones from your interface.
    Last edited by javapenguin; May 14th, 2012 at 01:28 PM.

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. 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, 08:29 AM