Main.java
public class Main
{ public Main()
{
} public static void main(String args[])
{
MainFrame frame1 = new MainFrame();
frame1.show();
}
}
MainFrame.java
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;public class MainFrame extends Frame{
public MainFrame()
{
setLayout(null);
setSize(700,500);
Button printButton;
Button kakusyukuButton;
printButton = new Button("印刷");
printButton.setBounds(980 - 120, 0, 100, 25);
add(printButton); kakusyukuButton = new Button("拡大表示");
add(kakusyukuButton);
kakusyukuButton.setBounds(980 - 230, 0, 100, 25); addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
dispose();
System.exit(0);
}
}); }
}
执行之后Form上怎么没有这两个Button啊
public class Main
{ public Main()
{
} public static void main(String args[])
{
MainFrame frame1 = new MainFrame();
frame1.show();
}
}
MainFrame.java
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;public class MainFrame extends Frame{
public MainFrame()
{
setLayout(null);
setSize(700,500);
Button printButton;
Button kakusyukuButton;
printButton = new Button("印刷");
printButton.setBounds(980 - 120, 0, 100, 25);
add(printButton); kakusyukuButton = new Button("拡大表示");
add(kakusyukuButton);
kakusyukuButton.setBounds(980 - 230, 0, 100, 25); addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
dispose();
System.exit(0);
}
}); }
}
执行之后Form上怎么没有这两个Button啊
class logFrame extends JFrame {
JPanel contentPane;
JTextField jTextField1 = new JTextField();
public logFrame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
} /**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(350, 177));
setTitle("欢迎登录");
jTextField1.setBounds(new Rectangle(106, 60, 104, 18));
contentPane.add(jTextField1);
}
}
public class st{
public static void main(String[] args){
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e){
throw new RuntimeException(e);
}
logFrame f=new logFrame();
f.show();
f.setLocation(350,250);
}
}
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import java.awt.Dimension;public class SwingWindow extends JFrame { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; // @jve:decl-index=0:visual-constraint="10,10"
private JButton btnOK = null;
private JLabel jLabelUser = null; private JTextField jTextUser = null; private JLabel jLabelPWD = null; private JPasswordField jPassword = null; private JButton jBtnClose = null;
/**
* This is the default constructor
*/
public SwingWindow() {
super();
initialize();
} /**
* This method initializes this
*
* @return void
*/
private void initialize() {
//this.setSize(300, 200);
this.setBounds(300, 300, 300, 174);
this.setContentPane(getJContentPane());
this.setTitle("Hello");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
} /**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabelPWD = new JLabel();
jLabelPWD.setBounds(new Rectangle(21, 66, 80, 20));
jLabelPWD.setText("密码:");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setSize(new Dimension(241, 120));
jContentPane.add(getjLabelUser());
jContentPane.add(getBtnOK());
jContentPane.add(getJTextUser(), null);
jContentPane.add(jLabelPWD, null);
jContentPane.add(getJPassword(), null);
jContentPane.add(getJBtnClose(), null);
}
return jContentPane;
}
private JButton getBtnOK()
{
btnOK = new JButton();
btnOK.setText("Show");
//btnOK.setSize(50,20);
btnOK.setBounds(40, 100, 67, 20);
btnOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
MyDialog dialog = new MyDialog();
dialog.setVisible(true);
System.out.println("OK Button actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
}
});
return btnOK;
}
private JLabel getjLabelUser()
{
jLabelUser = new JLabel();
jLabelUser.setText("用户名:");
jLabelUser.setBounds(20, 29, 80, 20);
return jLabelUser;
} /**
* This method initializes jTextMsg
*
* @return javax.swing.JTextField
*/
private JTextField getJTextUser() {
if (jTextUser == null) {
jTextUser = new JTextField();
jTextUser.setBounds(new Rectangle(131, 31, 98, 22));
}
return jTextUser;
} /**
* This method initializes jPassword
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPassword() {
if (jPassword == null) {
jPassword = new JPasswordField();
jPassword.setBounds(new Rectangle(130, 65, 99, 23));
}
return jPassword;
} /**
* This method initializes jBtnClose
*
* @return javax.swing.JButton
*/
private JButton getJBtnClose() {
if (jBtnClose == null) {
jBtnClose = new JButton();
jBtnClose.setBounds(new Rectangle(155, 100, 67, 19));
jBtnClose.setText("Close");
jBtnClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("Close Button actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
System.exit(0);
}
});
}
return jBtnClose;
}
}
this.setContentPane(new jContentPane));
jContentPane.setLayout(null);Button printButton;
printButton = new Button("印刷");
printButton.setBounds(980 - 120, 0, 100, 25);jContentPane.add(printButton);