java怎么创建窗口界面,java如何创建一个窗口出来

1,java如何创建一个窗口出来添加awt包import java.awt.*;继承extends JFrame设置窗口biaoti.setFont(new Font("微软雅黑",Font.BOLD,15));this.setSize(590,500 );this.setLocation(350, 100);this.setVisible(true);
2,如何用JAVA设计程序窗口import java.awt.*;import java.awt.event.*;import javax.swing.*;public class FrameTest private JFrame jf;private JButton yellow,blue,green;private JPanel panel1;public FrameTest()jf = new JFrame("Frame");yellow = new JButton("yellow");blue= new JButton("blue");green = new JButton("green");panel1 = new JPanel();panel1.setLayout(new FlowLayout());jf.add(panel1,BorderLayout.CENTER);jf.setVisible(true);jf.setSize(500,600);jf.addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0);}});blue.setForeground(Color.blue);panel1.add(blue);blue.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)panel1.setBackground(Color.blue);}});yellow.setForeground(Color.yellow);panel1.add(yellow);yellow.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)panel1.setBackground(Color.yellow);}});green.setForeground(Color.green);panel1.add(green);green.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)panel1.setBackground(Color.green);}});}public static void main(String args[])FrameTest ft = new FrameTest();}}
3,JAVA 创建简单的用户界面如果是说在一个窗体里面显示多个窗体,用JDesktopPane和JInternalFrame 。算了 , 帮你写了,自己改成windows风格 。喜欢Nimbus~~~~import javax.swing.*;import java.awt.*;public class InternalFrameDemo extends JFrameJDesktopPane desktop; public InternalFrameDemo()super("InternalFrameDemo"); int inset = 50; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset * 2); desktop = new JDesktopPane(); createFrame(100,100);//在(100,100)创建第一个内窗口 createFrame(150,150);//在(150,150)创建第二个内窗口 setContentPane(desktop); } protected void createFrame(int x,int y)JInternalFrame frame = new JInternalFrame("JInternalFrame", true, true, true, true); frame.setSize(300, 300); frame.setLocation(x, y); frame.setVisible(true); desktop.add(frame); } public static void main(String[] args)tryUIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (Exception ex)} InternalFrameDemo frame = new InternalFrameDemo(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }} 补充:哎,话说,你看清楚我代码没呢?createFrame(100,100);//在(100 , 100)创建第一个内窗口createFrame(150,150);//在(150,150)创建第二个内窗口这里创建了两个内窗口了,你自己去掉一个吧 。然后在内窗口里面显示“hello world”那个Panel的我就不写了,自己搞,不要连这么简单的都给你弄好了 。【java怎么创建窗口界面,java如何创建一个窗口出来】
4,怎么用java设计一个窗口要求功能如下刚刚写了段程序如下:-----------package demo;import java.awt.*;import java.awt.event.*;class MyActionEvent implements ActionListener{ private Test t; public MyActionEvent(Test t){this.t = t; } public void actionPerformed(ActionEvent e){Button btn = (Button)e.getSource();if(btn.getLabel().equals("Save file")){t.fdSave.setVisible(true);}else{t.fdOpen.setVisible(true);} }}public class Test{ Frame frame; Panel p; Button btnSave; Button btnOpen; FileDialog fdSave; FileDialog fdOpen; public Test(){frame = new Frame("FileDialog");p = new Panel();btnSave = new Button("Save file");btnSave.addActionListener(new MyActionEvent(this));btnOpen = new Button("Open file");btnOpen.addActionListener(new MyActionEvent(this));fdSave = new FileDialog(frame,"Save",FileDialog.SAVE);fdSave.setBounds(240,240,300,300);fdOpen = new FileDialog(frame,"Open",FileDialog.LOAD);fdOpen.setBounds(240,240,300,300);p.add(btnOpen);p.add(btnSave);frame.add(p,BorderLayout.SOUTH);frame.setBounds(200,200,300,200);frame.setVisible(true); } public static void main(String[]args){Test t = new Test(); }}---------------运行结果: 这不够优化5,用java做一个窗口java做窗口的话,需要用swing技术,之后创建JFrame 等组件,即可完成窗口创建工作 。package inter.frame;import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;public class MenuTest * @param args*/JFrame frame;//定义一个窗口架构JMenuBar mb;//定义窗口的菜单工具栏JMenu m; //定义菜单JMenuItem mi1;//定义菜单的内容JMenuItem mi2; //定义菜单的内容public MenuTest() initFrame();initAction();} public void initFrame() frame = new JFrame();mb = new JMenuBar();m = new JMenu("学生查询");mi1 = new JMenuItem("确认");mi2 = new JMenuItem("取消"); m.add(mi1);m.add(mi2);mb.add(m);frame.add(mb, BorderLayout.NORTH);frame.setSize(300, 300); //设置窗口大小frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置退出时关闭窗口frame.setVisible(true);//设置窗口可见} public void initAction() mi1.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) // 具体实现代码根据实际要求填写System.out.println("click");JOptionPane.showMessageDialog(null, "你点击了确定按钮");}});mi2.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) // 具体实现代码根据实际要求填写JOptionPane.showMessageDialog(null, "你点击了取消按钮");}});} public static void main(String[] args) new MenuTest();//执行菜单创建}}import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;public class Counter implements ActionListener public static void main(String[] args)new Counter(); } JFrame f; JButton b; JLabel l; JMenuBar mb; JMenu m; JMenuItem i1,i2; public Counter()f= new JFrame("计数器");f.getContentPane().setLayout(new FlowLayout(FlowLayout.RIGHT));f.setSize(200,98);f.setLocationRelativeTo(null);f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);b=new JButton("计数器");l=new JLabel("0");l.setPreferredSize(new Dimension(100,20));mb=new JMenuBar();m=new JMenu("文件菜单");i1=new JMenuItem("计数器");m.add(i1);i2.addActionListener(this);m.add(i2);mb.add(m);f.setJMenuBar(mb);f.getContentPane().add(l);f.getContentPane().add(b);f.setVisible(true);b.addActionListener(this);i1.addActionListener(this);i2=new JMenuItem("退出"); } private void plus()l.setText(String.valueOf(Integer.parseInt(l.getText())+1)); } public void actionPerformed(ActionEvent e)if(e.getActionCommand().equals("退出"))System.exit(0);elseplus(); }}import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; public class Count extends JFrameprivate static final long serialVersionUID = 1L; private JPanel panel; private JLabel lbl; private JButton btnCount; private JMenuBar menuBar; private JMenu menuFile; private JMenuItem menuItemCount; private JMenuItem menuItemExit; private String lblView = "0"; public void init()setTitle("Count"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); menuBar = new JMenuBar(); menuFile = new JMenu("File"); this.setJMenuBar(menuBar); menuBar.add(menuFile); menuItemCount = new JMenuItem("Count"); menuItemExit = new JMenuItem("Exit"); menuFile.add(menuItemCount); menuFile.add(menuItemExit); panel = new JPanel(); this.add(panel); lbl = new JLabel(lblView); btnCount = new JButton("Count"); panel.add(lbl); panel.add(btnCount); this.pack(); this.setVisible(true); addAction(); } public void addAction()btnCount.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) count(); } }); menuItemCount.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) count(); } }); menuItemExit.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) System.exit(0); } }); } public void count()int tep = Integer.parseInt(lbl.getText()); lblView = String.valueOf(tep+1); lbl.setText(lblView); } public static void main(String[] args) Count count = new Count(); count.init(); } } //楼上有错的,跑不起来//楼上要把i2=new JMenuItem("退出");放到前面 , i1=new JMenuItem("计数器");的后面与一楼的回答差不多

    推荐阅读