java executable jar
Napsal: 14 bře 2012 22:22
č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
to co je v poznámkách jsou přebytky, těch si nevšímejte...
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...