编写一个java应用程序
编写一个应用程序,创建如下图所示的界面,并按图片所示进行布局及颜色设置。(1)一个Frame对象,默认布局管理器(2)三个Panel对象(分别设置背景色,中间的Panel...
编写一个应用程序,创建如下图所示的界面,并按图片所示进行布局及颜色设置。
(1)一个Frame对象,默认布局管理器
(2)三个Panel对象(分别设置背景色,中间的Panel对象使用GridLayout布局管理器,其它两个默认)
(3)在三个Panel对象中分别添加按钮。 展开
(1)一个Frame对象,默认布局管理器
(2)三个Panel对象(分别设置背景色,中间的Panel对象使用GridLayout布局管理器,其它两个默认)
(3)在三个Panel对象中分别添加按钮。 展开
3个回答
展开全部
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class BroderLayoutDemo {
private static void showGUI(){
JFrame frame= new JFrame("flowLayoutDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel=new JPanel();
JPanel panelN=new JPanel();
panelN.setBackground(Color.YELLOW);
JPanel panelS=new JPanel();
panelS.setBackground(Color.PINK);
JPanel panelC=new JPanel();
panelC.setBackground(Color.BLUE);
frame.setSize(300, 200);
frame.setLocation(300, 200);
panel.setLayout(new BorderLayout());
JButton button1=new JButton("North1");
JButton button2=new JButton("North2");
JButton button3=new JButton("South1");
JButton button4=new JButton("South2");
JButton button5=new JButton("Center1");
JButton button6=new JButton("Center2");
JButton button7=new JButton("Center3");
panel.add(panelC,"Center");
panel.add(panelN,"North");
panel.add(panelS,"South");
panelN.setLayout(new FlowLayout());
panelN.add(button1);
panelN.add(button2);
panelS.setLayout(new FlowLayout());
panelS.add(button3);
panelS.add(button4);
panelC.setLayout(new GridLayout(2,2));
panelC.add(button5);
panelC.add(button6);
panelC.add(button7);
frame.add(panel);
frame.add(panel);
frame.setVisible(true);
}
public static void main(String args[]){
showGUI();
}
}
颜色有点不太准,可以自己下个工具调一下,写的好辛苦,希望能给分啊
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class BroderLayoutDemo {
private static void showGUI(){
JFrame frame= new JFrame("flowLayoutDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel=new JPanel();
JPanel panelN=new JPanel();
panelN.setBackground(Color.YELLOW);
JPanel panelS=new JPanel();
panelS.setBackground(Color.PINK);
JPanel panelC=new JPanel();
panelC.setBackground(Color.BLUE);
frame.setSize(300, 200);
frame.setLocation(300, 200);
panel.setLayout(new BorderLayout());
JButton button1=new JButton("North1");
JButton button2=new JButton("North2");
JButton button3=new JButton("South1");
JButton button4=new JButton("South2");
JButton button5=new JButton("Center1");
JButton button6=new JButton("Center2");
JButton button7=new JButton("Center3");
panel.add(panelC,"Center");
panel.add(panelN,"North");
panel.add(panelS,"South");
panelN.setLayout(new FlowLayout());
panelN.add(button1);
panelN.add(button2);
panelS.setLayout(new FlowLayout());
panelS.add(button3);
panelS.add(button4);
panelC.setLayout(new GridLayout(2,2));
panelC.add(button5);
panelC.add(button6);
panelC.add(button7);
frame.add(panel);
frame.add(panel);
frame.setVisible(true);
}
public static void main(String args[]){
showGUI();
}
}
颜色有点不太准,可以自己下个工具调一下,写的好辛苦,希望能给分啊
展开全部
有难度么?
package Test2;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestJFrame {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame jf = new JFrame("测试");
JPanel jp1 = new JPanel();
jp1.setLayout(new FlowLayout(FlowLayout.CENTER));
jp1.add(new JButton("Notrh1"));
jp1.add(new JButton("Notrh2"));
JPanel jp2 = new JPanel();
jp2.setLayout(new GridLayout(2,2));
jp2.add(new JButton("Center1"));
jp2.add(new JButton("Center2"));
jp2.add(new JButton("Center3"));
JPanel jp3 = new JPanel();
jp3.setLayout(new FlowLayout(FlowLayout.CENTER));
jp3.add(new JButton("South1"));
jp3.add(new JButton("South2"));
jp1.setBackground(Color.YELLOW);
jp2.setBackground(Color.BLUE);
jp3.setBackground(Color.RED);
jf.add(jp1,BorderLayout.NORTH);
jf.add(jp2,BorderLayout.CENTER);
jf.add(jp3,BorderLayout.SOUTH);
jf.setSize(300, 400);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
}
package Test2;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestJFrame {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame jf = new JFrame("测试");
JPanel jp1 = new JPanel();
jp1.setLayout(new FlowLayout(FlowLayout.CENTER));
jp1.add(new JButton("Notrh1"));
jp1.add(new JButton("Notrh2"));
JPanel jp2 = new JPanel();
jp2.setLayout(new GridLayout(2,2));
jp2.add(new JButton("Center1"));
jp2.add(new JButton("Center2"));
jp2.add(new JButton("Center3"));
JPanel jp3 = new JPanel();
jp3.setLayout(new FlowLayout(FlowLayout.CENTER));
jp3.add(new JButton("South1"));
jp3.add(new JButton("South2"));
jp1.setBackground(Color.YELLOW);
jp2.setBackground(Color.BLUE);
jp3.setBackground(Color.RED);
jf.add(jp1,BorderLayout.NORTH);
jf.add(jp2,BorderLayout.CENTER);
jf.add(jp3,BorderLayout.SOUTH);
jf.setSize(300, 400);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
哥们这是哪年的题?
还是awt和jbuilder
还是awt和jbuilder
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询