我從我的主類使用下面的調用創建另一個類的一個對象的Java漆:問題與框架
JSplash splash = new JSplash();
然而,當我創建這個對象它執行JSplash類的構造函數,並給出我的窗戶和我的按鈕。但它不會畫在畫框上。你能幫我解決這個問題嗎?
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 DFrame 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 = "";
private static int count = 1;
DFrame splash = new DFrame();
//Constructor
public JSplash() {
setDefaultLookAndFeelDecorated(true);
System.out.println("Hello");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
splash.add(myButton);
getContentPane().setBackground(bgColor);
//adds action listener
myButton.addActionListener(this);
splash.setVisible(true);
}
//Paint method
@Override
public void paint(Graphics e) {
System.out.println("paint is being reached");
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);
}
//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
{
splash.setVisible(false);
FinalProject app = new FinalProject();
}
}
}
對不起,油漆正在達到線我試圖看到該方法它不是 – 2012-07-23 06:17:10
添加了'splash.setLayout(新的BorderLayout());'然後改爲'add(myButton,BorderLayout.SOUTH);'沒有效果 – 2012-07-23 06:25:57
爲了更好的幫助, [SSCCE](http://sscce.org/)。 – 2012-07-23 06:27:23