我想知道我应该把所有的 CONSTANTS 放在哪里,以便我的 Java 项目中的所有包和类都可以访问它们?我如何将它包含在下面的主要课程中?
我有一个经典的 ASP 背景,很抱歉到目前为止代码中的任何错误。
StickyNotes() 类。
package base;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
public class StickyNotes extends JFrame {
private static final long serialVersionUID = 1L;
private final static String SAVE_CHNGS = "Save changes?";
private final static String TITLE_AYS = "Are You Sure?";
private void createStickyNotesGUI() {
// Create and set up the window.
JFrame frame = new JFrame("Java Sticky Notes");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout(FlowLayout.LEFT));
// Add Main Menu
MainMenuBar mainMenu = new MainMenuBar();
frame.setJMenuBar(mainMenu.createMainMenuBar(frame));
// Add Content Pane // can I pass a layout object?
frame.setContentPane(ContentPaneCreator.createContentPane());
// contentPane.add(scrollPane, BorderLayout.CENTER);
// Add Tool Bar
ToolBarCreator toolBar = new ToolBarCreator();
frame.getContentPane().add(toolBar.createToolBar(), BorderLayout.NORTH);
// Add Label
frame.getContentPane().add(
LabelCreator.createLabel(frame,
"use Swing and JavaFX together."), BorderLayout.NORTH);
// Display the window.
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
// frame.setExtendedState(JFrame.NORMAL);
frame.setVisible(true);
}
public void doExit(JFrame frame) {
boolean fDirty = true;
if (fDirty)
switch (JOptionPane.showConfirmDialog(StickyNotes.this, SAVE_CHNGS,
TITLE_AYS, JOptionPane.YES_NO_OPTION)) {
case JOptionPane.YES_OPTION:
// if (doSave())
frame.dispose();
break;
case JOptionPane.NO_OPTION:
frame.dispose();
}
else
frame.dispose();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new StickyNotes().createStickyNotesGUI();
}
});
}
}