我已经jar
使用 Netbeans 构建了一个文件,它在我的系统中运行良好。但是我想制作jar
能够在所有具有 JRE 的系统中运行的文件,即使classpath
没有在该系统中设置它也应该可以正常工作。
package circle;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class Circle {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Circle().createAndShowGUI();
}
});
}
private void createAndShowGUI() {
JFrame f = new JFrame("Swing Paint Demo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new MyPanel());
f.pack();
f.setVisible(true);
}
class MyPanel extends JPanel {
public MyPanel() {
setBorder(BorderFactory.createLineBorder(Color.black));
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
startX=e.getX();
startY=e.getY();
}
});
addMouseMotionListener(new MouseAdapter() {
public void mouseDragged(MouseEvent e) {
X=e.getX();
Y=e.getY();
repaint();
}
});
}
public Dimension getPreferredSize() {
return new Dimension(250,200);
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
//g.setColor(Color.RED);
//g.fillRect(squareX,squareY,squareW,squareH);
g.setColor(Color.BLACK);
g.drawOval(startX,startY,X-startX,Y-startY);
g.fillOval(startX,startY,X-startX,Y-startY);
}
}
private int startX,startY,X,Y;
}