当我尝试打开一个新框架时,我无法隐藏新框架。在这段代码的末尾有一个调用另一个类的start()方法,我希望隐藏这个类框架,但我似乎无法从当前位置访问它。
package InventoryApp;
//Import
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
/**
*
* @author Curtis
*/
public class JSplash extends JFrame implements ActionListener
{
//declaration of variable objects
Font myFont = new Font("Arial", Font.BOLD, 20);
JButton myButton = new JButton("Click Me!");
Color bgColor = new Color(0,0,255);
Color firstColor = new Color(255,255,255);
String first = "Welcome to DaemoDynamics!";
String last = "Click the Button";
String middle = "";
String middle2 = "";
int count = 1;
//Constructor
public JSplash()
{
super("Item Inventory Application");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout (new BorderLayout());
add(myButton, BorderLayout.SOUTH);
setDefaultLookAndFeelDecorated(true);
getContentPane().setBackground(bgColor);
//adds action listener
myButton.addActionListener(this);
}
//Paint method
@Override
public void paint(Graphics e)
{
super.paint(e);
e.setFont(myFont);
e.setColor(firstColor);
e.drawString(first, 14, 80);
e.drawString(last, 70, 240);
e.drawString(middle, 75, 150);
e.drawString(middle2, 60, 175);
}
public static void begin()
{
final int TALL = 316;
final int WIDE = 304;
JSplash frame = new JSplash();
frame.setSize(WIDE, TALL);
frame.setVisible(true);
}
//Listener Method
@Override
public void actionPerformed(ActionEvent e)
{
//First Time button hit
if(count == 1)
{
middle = "Brighter Business";
middle2 = "for A Brighter Future";
last = "Click Again to Begin";
repaint();
//increases button count
count ++;
}
else//if button count is not 1
{
frame.setVisible(false);
FinalProject.start();
}
}
}
答案 0 :(得分:0)
frame
被声明为局部变量,因此超出了actionPerformed()
方法的范围。