|
查看: 1043|回复: 16
|
Java Constructor + Screen Layout Question
[复制链接]
|
|
|
本帖最后由 雪儿与小鱼儿 于 9-3-2010 01:09 PM 编辑
各位,
我要 define a class called Day with a default constructor。
以下是我的 code:
- public class Day
- {
- private int dayNumber;
- public Day()
- {
- dayNumber = 1;
- }//End constructor
- }//End class Day
复制代码
请各位帮我看一下对吗?
谢谢。 |
|
|
|
|
|
|
|
|
|
|
发表于 8-3-2010 01:29 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 8-3-2010 01:35 PM
|
显示全部楼层
compile 下看看可不可以跑就可以啦..
就算不可跑, 也会有err msg 出现..
新手就是要学看err msg..  |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 8-3-2010 02:48 PM
|
显示全部楼层
请问你们用什么 compiler 呢?
我用 windows 的 command prompt。 |
|
|
|
|
|
|
|
|
|
|
发表于 8-3-2010 02:50 PM
|
显示全部楼层
可以试试 ECLIPSE / NETBEAN  |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 8-3-2010 02:54 PM
|
显示全部楼层
|
请问 input function 是指 get input from user 吗? |
|
|
|
|
|
|
|
|
|
|
发表于 9-3-2010 12:02 AM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 9-3-2010 01:08 PM
|
显示全部楼层
我还有问题要问:
如果我要弄到以下的 screen ,我应该要用什么格式的 layout 呢?Box or Panel or Grid?
 |
|
|
|
|
|
|
|
|
|
|
发表于 9-3-2010 05:51 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 9-3-2010 05:56 PM
|
显示全部楼层
一直 FLOW 下去 就 可以了 。。。。。
兔仙人 发表于 9-3-2010 05:51 PM 
可是要怎样把那些 buttons 移进一点?  |
|
|
|
|
|
|
|
|
|
|
发表于 9-3-2010 06:04 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 9-3-2010 07:05 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 9-3-2010 08:34 PM
|
显示全部楼层
|
可以 POST 你的 CODE 上来吗 ? 我帮你 看看 |
|
|
|
|
|
|
|
|
|
|
发表于 9-3-2010 08:34 PM
|
显示全部楼层
|
可以 POST 你的 CODE 上来吗 ? 我帮你 看看 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 10-3-2010 08:16 AM
|
显示全部楼层
可以 POST 你的 CODE 上来吗 ? 我帮你 看看
兔仙人 发表于 9-3-2010 08:34 PM 
- import java.applet.Applet;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.Box;
- import javax.swing.BoxLayout;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JMenu;
- import javax.swing.JMenuItem;
- import javax.swing.JMenuBar;
- import javax.swing.JPanel;
- import javax.swing.JTextArea;
- public class TestFrame extends JFrame
- {
- private FlowLayout layout;
- private Container container;
- private Box vertical2;
- private JPanel panel1;
- private JPanel panel2;
- private JButton button1;
- private JButton button2;
- private JButton button3;
- private JButton button4;
- private JButton button5;
- private JButton button6;
- private JComboBox comboDay;
- private JComboBox comboMonth;
- private JComboBox comboYear;
- private JTextArea textArea1;
- private JTextArea textArea2;
- // no-argument constructor set up GUI
- public TestFrame()
- {
- super ( "TestFrame.java" );
- // layout = new FlowLayout();
- // container = getContentPane();
- // setLayout( layout );
- JPanel panel1 = new JPanel();
- JPanel panel2 = new JPanel();
- JPanel panel3 = new JPanel();
- Box vertical2 = Box.createVerticalBox();
- //set menu bar
- JMenu fileMenu = new JMenu( "Applet" ); // create file menu
- JMenuBar bar = new JMenuBar(); // create menu bar
- setJMenuBar( bar ); // add menu bar to application
- bar.add( fileMenu ); // add file menu to menu bar
- //set combo box
- String day[] = {"1"};
- String month[] = {"January"};
- String year[] = {"1999"};
- comboDay = new JComboBox(day);
- comboMonth = new JComboBox(month);
- comboYear = new JComboBox(year);
- //set text area 1
- textArea1 = new JTextArea( 10,20 );
- //set text area 2
- textArea2 = new JTextArea( 6,15 );
- //set button 1
- button1 = new JButton( "Test 1" );
- panel1.setLayout (new FlowLayout (FlowLayout.LEFT));
- // panel1.setLayout (new GridLayout (1,1));
- panel1.add(comboDay);
- panel1.add(comboMonth);
- panel1.add(comboYear);
- panel1.add(textArea1);
- panel1.add(textArea2);
- panel1.add(button1);
- add("Center", panel1);
- // add(panel1, BorderLayout.NORTH);
- //set button 2
- button2 = new JButton( "Test 2" );
- button2.setPreferredSize(new Dimension(100, 25));
- //set button 3
- button3 = new JButton( "Test3" );
- button3.setPreferredSize(new Dimension(100, 25));
- //set button 4
- button4 = new JButton( "Test Button 4" );
- button4.setPreferredSize(new Dimension(100, 25));
- //set button 5
- button5 = new JButton( "5" );
- button5.setPreferredSize(new Dimension(100, 25));
- //set button 6
- button6 = new JButton( "Exit" );
- button6.setPreferredSize(new Dimension(100, 25));
- panel2.setLayout (new BoxLayout (panel2, BoxLayout.Y_AXIS) );
- //// panel2.setLayout (null);
- //// panel2.setLayout (new FlowLayout (FlowLayout.CENTER));
- //// panel2.setLayout (new BorderLayout (5,5));
- // panel2.setLayout (new GridLayout (5,1));
- // panel2.add (button2);
- // panel2.add (button3);
- // panel2.add (button4);
- // panel2.add (button5);
- // panel2.add (button6);
- vertical2.add( Box.createRigidArea( new Dimension( 12, 1 ) ) );
- vertical2.add (button2);
- vertical2.add( Box.createRigidArea( new Dimension( 12, 1 ) ) );
- vertical2.add (button3);
- vertical2.add( Box.createRigidArea( new Dimension( 12, 1 ) ) );
- vertical2.add (button4);
- vertical2.add( Box.createRigidArea( new Dimension( 12, 1 ) ) );
- vertical2.add (button5);
- vertical2.add( Box.createRigidArea( new Dimension( 12, 1 ) ) );
- vertical2.add (button6);
- panel2.add (vertical2);
- panel1.add (panel2);
- }// end constructor
- } //end class TestFrame
复制代码
以上是 applet 的 code,请帮忙看一下。  |
|
|
|
|
|
|
|
|
|
|
发表于 11-3-2010 06:02 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 12-3-2010 02:12 PM
|
显示全部楼层
本帖最后由 algorithm 于 12-3-2010 02:14 PM 编辑
- JFrame frame = new JFrame();
- JTextArea textArea = new JTextArea();
- JPanel panel = new JPanel();
- panel.setLayout(new BoxLayout(p,BoxLayout.Y_AXIS));
- JButton button = new JButton("button1");
- button.setAlignmentX(Component.CENTER_ALIGNMENT);
- panel.add(button);
-
- frame.add(textArea,BorderLayout.NORTH);
- frame.add(panel,BorderLayout.CENTER);
复制代码 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|