import javax.swing.*;
import java.awt.*;
public class Painter extends JPanel{
public Painter(){
buildGUI();
}
private void buildGUI(){
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setTitle("Paint drawing demonstration");
new Center_frame(frame);
JPanel headerPanel = new JPanel();
headerPanel.add(new JLabel("The drawing panel is below"));
Drawing_panel dp = new Drawing_panel();
frame.add(BorderLayout.NORTH,headerPanel);
frame.add(BorderLayout.SOUTH,dp);
frame.pack();
frame.setVisible(true);
}
public static void main(String args[]){
new Painter();
}
}//end class Painter
例2、私が好むだろうけれども、それらの両方がほぼ均等に "正しい"( "正しい" :-)の一つの定義に依存している
import javax.swing.*;
import java.awt.*;
public class Painter extends JPanel{
public Painter(){
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setTitle("Paint drawing demonstration");
new Center_frame(frame);
JPanel headerPanel = new JPanel();
headerPanel.add(new JLabel("The drawing panel is below"));
Drawing_panel dp = new Drawing_panel();
frame.add(BorderLayout.NORTH,headerPanel);
frame.add(BorderLayout.SOUTH,dp);
frame.pack();
frame.setVisible(true);
}
public static void main(String args[]){
//create a Painter object
new Painter();
}
}//end class Painter
これらは本質的に同じです。 – mrkhrts
どちらが使えますか? 「正しい」とはどういう意味ですか?あなたはどちらが良いと思いますか、なぜですか?また、http://codereview.stackexchange.com。 –
それはまあそれに依存します。コンストラクタの外で 'buildGUI()'を使うつもりはありますか? – NullUserException