java SWING小程序

java SWING小程序,第1张

因为你把显示语句的方法体模和悔定义在了Jpanelscreena的有参构造器中,而你Jpanelscreena jll=new Jpanelscreena()这一句调用的确实无参构造器,这样的话,有参构造器当中的方法体当然不会被执行啦。改法如棚改下旦正:

import java.awt.*

import javax.swing.*

public class JPanelDemo {

public static void main(String args[]) {

JFrameDemoa jf = new JFrameDemoa()

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

jf.setVisible(true)

}

}

class JFrameDemoa extends JFrame {

public JFrameDemoa() {

this.setTitle("nihao")

this.setBounds(100, 100, 200, 200)

Jpanelscreena jll = new Jpanelscreena()

add(jll)

}

}

class Jpanelscreena extends JPanel {

private int width = 20

private int height = 20

public void paintComponnet() {

}

public void paint(Graphics g) {

super.paintComponent(g)

g.drawString("Java is money", 20, 20)

}

}

记得给我分哦^_^

import java.awt.Container

import java.awt.event.ActionEvent

import java.awt.event.ActionListener

import javax.swing.JButton

import javax.swing.JFrame

import javax.swing.JTextArea

public class RemoveAllFrame extends JFrame implements ActionListener {

    private static final long 渣卖蔽serialVersionUID = 20111111111L

    private JButton removeAllButton = new JButton("RemoveAll")

    private JTextArea textArea = 配碧new JTextArea("点击RemoveAll....")

    public RemoveAllFrame() {

        super("RemoveAll Demo")

        try {

            init()

        } catch (Exception e) {

            e.printStackTrace()

        }

    }

    private void init() {

        removeAllButton.setBounds(220, 50, 100, 25)

        textArea.setBounds(10, 10, 200, 200)

        removeAllButton.addActionListener(this)

        Container c = getContentPane()

        c.setLayout(null)

        c.add(removeAllButton)

        c.add(textArea)

        this.setSize(400, 300)

        this.setResizable(false)

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

        this.setLocationRelativeTo(null)

        this.setVisible(true)

    }

    public static void main(String[] args) {

        new RemoveAllFrame()

    }

    public void actionPerformed(ActionEvent e) {

        if (e.getSource() == removeAllButton) {

            System.out.println("ok")

            getContentPane().removeAll()

            getContentPane().repaint()

        }

 如州   }

}

import javax.swing.*

public class Swing {

JFrame frame

JPanel panel

JLabel jla1,jla2,jla3

JButton jbu

JTextField jtf1,jtf2

JComboBox box

static final String[] email={"正滑263.net","163.com","qq.com"}

public Swing(){

frame=new JFrame()

frame.setSize(600,300)

frame.setLocation(200,100)

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

frame.setVisible(true)

jla1=new JLabel("邮举做腊箱胡配")

jla2=new JLabel("@")

jla3=new JLabel("密码")

jtf1=new JTextField("用户名",10)

jtf2=new JTextField("密码",10)

box=new JComboBox(email)

jbu=new JButton("登陆")

panel=new JPanel()

panel.add(jla1)

panel.add(jtf1)

panel.add(jla2)

panel.add(box)

panel.add(jla3)

panel.add(jtf2)

panel.add(jbu)

frame.add(panel)

}

public static void main(String args[]){

new Swing()

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12236703.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-22
下一篇 2023-05-22

发表评论

登录后才能评论

评论列表(0条)

保存