java 图形界面编程问题
第一道:编写继承自JFrame类的窗口应用程序,其内容面板为边框布局。窗口内容面板的北边放置一个面板,该面板的布局为3*3的网格布局,放置9个按钮。南边放置一个面板,该面...
第一道:编写继承自JFrame类的窗口应用程序,其内容面板为边框布局。窗口内容面板的北边放置一个面板,该面板的布局为3*3的网格布局,放置9个按钮。南边放置一个面板,该面板的布局为1*2的网格布局,放置2个文本区。第二道:编写继承自JAapplet类的小程序,其内容面板的布局为边框布局。小程序窗口的南边放置一个面板类对象,面板的布局为缺省的流式布局,面板中放置5个按钮;小程序窗口的北边放置一个面板类对象,面板的布局为缺省的流式布局,面板中放置5个按钮;小程序窗口中间放置1个文本区。
展开
1个回答
2013-11-13
展开全部
package Test1;
import java.awt.*;
import javax.swing.*;
class Jie5 extends JFrame {
JPanel contentPane, northPanel, southPanel;
JTextField jtf1, jtf2;
JButton jb[];
public Jie5() {
contentPane = new JPanel();
northPanel = new JPanel();
southPanel = new JPanel();
jtf1 = new JTextField();
jtf2 = new JTextField();
jb = new JButton[10];
this.setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(4,4));
contentPane.add(northPanel,BorderLayout.NORTH);
northPanel.setLayout(new GridLayout(3, 3, 4, 4));
for(int i = 0; i < 9 ; i ++)
{
jb[i] = new JButton(""+(i+1));
northPanel.add(jb[i]);
}
contentPane.add(southPanel,BorderLayout.SOUTH);
southPanel.setLayout(new GridLayout(1,2,4,4));
southPanel.add(jtf1);
jtf1.setColumns(10);
southPanel.add(jtf2);
jtf2.setColumns(10);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(30,30,400,400);
this.setTitle("hello");
}
}
public class Demo5 {
/**
* @param args
*/
public static void main(String[] args) {
try {
// TODO Auto-generated method stub
UIManager
.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
EventQueue.invokeLater(new Runnable(){
@Override
public void run()
{
Jie5 jie5 = new Jie5();
jie5.setVisible(true);
}
});
}
}
import java.awt.*;
import javax.swing.*;
class Jie5 extends JFrame {
JPanel contentPane, northPanel, southPanel;
JTextField jtf1, jtf2;
JButton jb[];
public Jie5() {
contentPane = new JPanel();
northPanel = new JPanel();
southPanel = new JPanel();
jtf1 = new JTextField();
jtf2 = new JTextField();
jb = new JButton[10];
this.setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(4,4));
contentPane.add(northPanel,BorderLayout.NORTH);
northPanel.setLayout(new GridLayout(3, 3, 4, 4));
for(int i = 0; i < 9 ; i ++)
{
jb[i] = new JButton(""+(i+1));
northPanel.add(jb[i]);
}
contentPane.add(southPanel,BorderLayout.SOUTH);
southPanel.setLayout(new GridLayout(1,2,4,4));
southPanel.add(jtf1);
jtf1.setColumns(10);
southPanel.add(jtf2);
jtf2.setColumns(10);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(30,30,400,400);
this.setTitle("hello");
}
}
public class Demo5 {
/**
* @param args
*/
public static void main(String[] args) {
try {
// TODO Auto-generated method stub
UIManager
.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
EventQueue.invokeLater(new Runnable(){
@Override
public void run()
{
Jie5 jie5 = new Jie5();
jie5.setVisible(true);
}
});
}
}
--
2022-12-05 广告
2022-12-05 广告
图形化编程简单理解为用积木块形式编程,scratch和python也是其中的一种,属于入门级编程,以其简单生动的画面获得无数学生的喜爱,深圳市创客火科技有限公司是一家做教育无人机的公司,旗下有编程无人机,积木无人机及室内外编队,每款飞机含有...
点击进入详情页
本回答由--提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询