Demo entry 6799708

py

   

Submitted by anonymous on May 21, 2019 at 12:10
Language: Java. Code size: 2.9 kB.

/*
 * MainFrame.java
 
 */

package com;

import com.controller.Controller;
import com.model.CircleModel;
import com.view.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class MainFrame extends JFrame{
    public CircleModel model;
    public ViewPanel vp;
    public RTextField rTextField;
    public DTextField dTextField;//添加直径文本框
    public CTextField cTextField;
    public STextField sTextField;
    public ControlSlider slider;
    public BTextField bTextField;
    private JPanel topPanel = new JPanel();
    private JPanel bottomPanel = new JPanel();
    public JButton jButton1 = new JButton("更新");
    private JLabel jLabel1 = new JLabel("半径");
    private JLabel jLabel1_1 = new JLabel("直径");//添加直径标签
    private JLabel jLabel2 = new JLabel("周长");
    private JLabel jLabel3 = new JLabel("面积");
    private JLabel jLabel4 = new JLabel("球面积");
    
    /** Creates a new instance of MainFrame */
    public MainFrame(String title) {
        super.setTitle(title);
        initComponent();
        new Controller(this);
    }
    
    private void initComponent(){
        model=new CircleModel(10.0);
        vp = new ViewPanel(model);
        rTextField = new RTextField(model);
        dTextField = new DTextField(model);//直径
        cTextField = new CTextField(model);
        sTextField = new STextField(model);
        bTextField = new BTextField(model);
        slider = new ControlSlider(model);
        cTextField.setEditable(false);
        sTextField.setEditable(false);
        bTextField.setEditable(false);
        dTextField.setEditable(false);//直径不可修改
        topPanel.setLayout(new FlowLayout());
        topPanel.add(jLabel1);
        topPanel.add(rTextField);
        topPanel.add(jButton1);
        slider.setValue(10);
        topPanel.add(slider);
        bottomPanel.setLayout(new FlowLayout());
        bottomPanel.add(jLabel2);
        bottomPanel.add(cTextField);
        bottomPanel.add(jLabel3);
        bottomPanel.add(sTextField);
        bottomPanel.add(jLabel4);
        bottomPanel.add(bTextField);
        bottomPanel.add(jLabel1_1);
        bottomPanel.add(dTextField);


        this.getContentPane().setLayout(new BorderLayout());
        this.getContentPane().add(topPanel,BorderLayout.NORTH);
        this.getContentPane().add(vp,BorderLayout.CENTER);
        this.getContentPane().add(bottomPanel,BorderLayout.SOUTH);
        this.setSize(640,480); 
        this.addWindowListener(new WindowAdapter(){ 
        public void windowClosing(WindowEvent e) { 
            System.exit(0); 
            } 
        }); 

    }
    
    public static void main(String[] args) {
        // TODO code application logic here
        MainFrame mf = new MainFrame("MVC练习 ");
        mf.setVisible(true);
    }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).