一段最简单的窗口设计的Java程序,(能输入字符串,提供处理按钮,以及完整的退出体系代码)import java.awt.event.*;
import javax.swing.*;
public class TestFrame extends JFrame implements ActionListener{
JLabel lb1,lb2;
JTextField jtf;
JButton bt;
public TestFrame(){
init();
}
private void init(){
this.setLayout(null);
lb1 = new JLabel("请输入字符串:");
lb1.setBounds(10, 10, 100, 20);
lb2 = new JLabel("输入为:");
lb2.setBounds(120,10 , 100, 20);
jtf = new JTextField(10);
jtf.setBounds(10, 50, 100, 20);
bt = new JButton("确定");
bt.addActionListener(this);
bt.setBounds(120, 50, 60, 30);
this.add(lb1);
this.add(lb2);
this.add(jtf);
this.add(bt);
this.setSize(400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setVisible(true);
}
public static void main(String args[]){
new TestFrame();
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==bt!jtf.getText().trim().equals("")){
lb2.setText("输入为:" jtf.getText().trim());
}else{
jtf.setText("");
JOptionPane.showMessageDialog(this, "格式不合法");
}
}
}
}
Java编写一个简单的窗口程序 , 流程是什么?import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test3 extends JFrame implements ActionListener{
JMenu m;
JMenuItem mi1,mi2;
JMenuBar mb;
public Test3(){
m = new JMenu("学生查询");
mi1 = new JMenuItem("确认");
mi2 = new JMenuItem("取消");
mb = new JMenuBar();
m.add(mi1);
m.add(mi2);
mb.add(m);
this.setJMenuBar(mb);
this.setSize(400,300);
this.setLocationRelativeTo(null);//窗口居中
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mi1.addActionListener(this);
mi2.addActionListener(this);
}
public static void main(String[] args){
new Test3();
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==mi1){
JOptionPane.showMessageDialog(null, "你点击了确定按钮");}else{
【java窗口程序完整代码 java编写窗口】JOptionPane.showMessageDialog(null, "你点击了取消按钮");}
}
}
求java窗口程序编程?package window;
import java.awt.Container;
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.JTextArea;
import javax.swing.JTextField;
public class Window extends JFrame{
public static int num = 0;
public static void main(String[] args) {
new Window();
}
public Window(){
//设置x y坐标
this.setLocation(400, 500);
//设置窗口大小
this.setSize(512, 512);
//设置窗口可见
this.setVisible(true);
//设置窗口关闭后程序停止
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//设置窗口不可移动
this.setResizable(false);
JButton but1 = new JButton("按钮");
final JTextField text1 = new JTextField(10);
写出完整的java程序,实现一个有按钮的窗口,按钮名字为“请点击” 。要怎么写?我这里有个最基本的用法,你可以参考一下
import java.awt.*;
import java.awt.event.*;
public class TestA extends Frame {
Button bt = new Button("请点击");
TestA() {
setLayout(null);
// 关闭窗口
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setBounds(200, 100, 200, 200);
setTitle("小窗口");
setVisible(true);
bt.setBounds(50,50,40,20);
add(bt);
}
public static void main(String[] args) {
new TestA();
}
}
java编写有窗口界面应用程序 求代码package image;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class PanelRunner extends JFrame
{
private static final long serialVersionUID = 1L;
private static void initPanels ( JFrame pr )
{
for ( int i = 0; i5; i)
{
JPanel panel = new JPanel ();
switch (i)
{
case 0:
panel.setBackground (Color.RED);
panel.setPreferredSize (new Dimension (200, 100));
pr.add (panel, BorderLayout.NORTH);
break;
case 1:
panel.setBackground (Color.YELLOW);
panel.setPreferredSize (new Dimension (200, 300));
pr.add (panel, BorderLayout.EAST);
break;
case 2:
panel.setBackground (Color.ORANGE);
panel.setPreferredSize (new Dimension (200, 100));
pr.add (panel, BorderLayout.SOUTH);
break;
case 3:
panel.setBackground (Color.WHITE);
panel.setPreferredSize (new Dimension (200, 300));
pr.add (panel, BorderLayout.WEST);
break;
case 4:
pr.add (panel, BorderLayout.CENTER);
panel.setPreferredSize (new Dimension (200, 100));
panel.setLayout (new GridLayout (1, 2));
for ( int j = 0; j2; j)
{
JPanel subPanel = new JPanel ();
subPanel.setPreferredSize (new Dimension (200, 100));
Color color = j == 0 ? Color.BLUE : Color.GREEN;
subPanel.setBackground (color);
panel.add (subPanel);
}
break;
default:
break;
}
}
}
private static void initFrame ( JFrame pr )
{
pr.setLayout (new BorderLayout ());
pr.setSize (600, 300);
pr.setLocationRelativeTo (null);
pr.setResizable (false);
pr.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}
public static void main ( String[] args )
{
SwingUtilities.invokeLater (new Runnable ()
{
@Override
public void run ()
{
PanelRunner pr = new PanelRunner ();
initFrame (pr);
initPanels (pr);
pr.setVisible (true);
}
});
}
}
java窗口程序完整代码的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于java编写窗口、java窗口程序完整代码的信息别忘了在本站进行查找喔 。
推荐阅读
- 怎么查路由器网管密码密码,怎么查路由器网管密码密码是多少
- html家居网模板,家居网页设计
- 外国人玩模拟飞行手机游戏,外国人玩模拟飞行手机游戏视频
- 努比亚z17刷鸿蒙系统,努比亚z17刷miui11
- python中cor函数 python cov函数
- oculus电脑怎么连接,oculus链接电脑
- 电脑怎么设置u盘进入系统,电脑怎么设置进去u盘
- 如何练习游戏动作,游戏训练方法
- python与c函数交互 c和python交互