Stránka 1 z 1

java executable jar

Napsal: 14 bře 2012 22:22
od honzaik
čau poprvé jsem se snažil něco splácat v javě se swingem. normálně to funguje jak má, ale když to vyexportuju v Eclipse jako Runnable jar file, tak to napíše že to nemůže najít main class.. poradí mi někdo co s tím? v javě jsem uplný začátečník, takže jsem rád za každou radu :)
tady je kod

Kód: Vybrat vše

package com;

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

import javax.swing.*;

public class Main {
   
   public static void main(String[] args) {
      JFrame okno = new JFrame();
      BorderLayout bl = new BorderLayout();
      
      Font serif = new Font("Serif", Font.PLAIN, 20);
      
      /* final JButton tlacitko1 = new JButton();
      final JButton tlacitko2 = new JButton();
      */
      final JButton tlacitko3 = new JButton();
      // final JTextField textField1 = new JTextField();
      final JLabel onScreenText = new JLabel();
      
      Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
      
      okno.setSize(screen.width / 2, screen.height / 2);
      okno.setLocation(screen.width / 4, screen.height / 4);
      okno.setVisible(true);
      okno.setTitle("TEXTT!!!");
      okno.setBackground(barva);
      okno.setResizable(false);
      
      int windowWidth = okno.getWidth();
      int windowHeight = okno.getHeight();
      
      /*
      tlacitko1.setText(windowWidth + " a " + windowHeight);
      tlacitko1.setBounds(new Rectangle(windowWidth / 2 - 250, 100, 500, 100));
      
      tlacitko2.setText("HELLO DERE!!!!");
      tlacitko2.setBounds(new Rectangle(windowWidth / 2 - 200, windowHeight / 2 , 400, 100));
      tlacitko2.addActionListener(
            new java.awt.event.ActionListener(){
               public void actionPerformed(ActionEvent e){
                  int windowWidth = getWidth();
                  int windowHeight = getHeight();
                  tlacitko1.setBounds(new Rectangle(windowWidth / 2 - 250, 100, 500, 100));
                  tlacitko2.setBounds(new Rectangle(windowWidth / 2 - 200, windowHeight / 2 , 400, 100));
                  String newValue = textField1.getText();
                  tlacitko1.setText(windowWidth + " a " + windowHeight + " value = "+ newLine + newValue);
               }
            }
      );
      
      */
      
      tlacitko3.setText("EXIT");
      tlacitko3.addActionListener(
            new java.awt.event.ActionListener(){
               public void actionPerformed(ActionEvent e){
                  System.exit(1);
               }
            }
      );
      
      // textField1.setBounds(new Rectangle(0,0, 100, 30));
      
      String text = "Helloooooo";
      onScreenText.setText(text);
      onScreenText.setHorizontalAlignment((int) Component.CENTER_ALIGNMENT);
      onScreenText.setFont(serif);
      onScreenText.setBounds(new Rectangle(windowWidth / 2 - 300, 0, 600, windowHeight));
      
      /* getContentPane().add(tlacitko1);
      getContentPane().add(tlacitko2);
      getContentPane().add(textField1);
      */
      okno.getContentPane().add(onScreenText);
      
      okno.getContentPane().setLayout(bl);
      okno.getContentPane().add(tlacitko3, BorderLayout.SOUTH);
      
      okno.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }

}


to co je v poznámkách jsou přebytky, těch si nevšímejte...

Re: java executable jar

Napsal: 15 bře 2012 14:07
od martas01
Musis tam tu tridu Main nekde oznacit jako ze je to ta ve ktere je meoda public static void main(String[] args) tudiz ze se to s ni ma spoustet...
http://www.youtube.com/watch?v=Czmc2-hSBuk

Re: java executable jar

Napsal: 15 bře 2012 15:56
od honzaik
no právě že když se to všechno vytvoří v tý metodě, tak to neni potřeba myslim... ikdyž pro ten "program" udělám vlastní třídu a v týhle napíšu do té metody public static void main.... { new Okno() } tak to napíše stejně tu chybu :(

Re: java executable jar

Napsal: 24 bře 2012 14:53
od honzaik
už to jde... asi špatně nastavenou javou