⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 movieitemview.java

📁 绝对经典!好动西和大家一起分享 呵呵 你们不应该如此限制的,不好
💻 JAVA
字号:
/* * MovieItemView - the item View for the MovieCat model. * This implements a view of a single item - the current movie. * Copyright (c) 2001, Bruce E. Wampler */import java.util.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class MovieItemView        extends		WmvcView	implements	ActionListener	// for buttons{    protected GridBagLayout gridbag;    protected GridBagConstraints c;    private JPanel itemPanel;    private MovieModel myModel;		// local copy    // Various components needed for constructing the view    // We use private statics of each of these since there will    // be only one instance of the itemView    private static JLabel lblTitle=new JLabel("Movie Title: ");    private static JLabel fldTitle = new JLabel(" ");    private static JLabel lblDirector=new JLabel("Director: ");    private static JLabel fldDirector = new JLabel(" ");    private static JLabel lblYear = new JLabel("Year: ");    private static JLabel fldYear = new JLabel(" ");    private static JLabel lblRating = new JLabel("Rating: ");    private static JLabel fldRating = new JLabel(" ");    private static JLabel lblGenre = new JLabel("   Genre: ");    private static JLabel fldGenre = new JLabel(" ");    private static JLabel lblFormat = new JLabel("   Format: ");    private static JLabel fldFormat = new JLabel(" ");    private static JLabel lblLabel = new JLabel("   Label: ");    private static JLabel fldLabel = new JLabel(" ");    private static JLabel lblEvaluation =     				new JLabel("My Rating: ");    private static JLabel fldEvaluation = new JLabel(" ");    private static JLabel lblComments=new JLabel("Comments: ");    private static JTextArea textArea;    private static JButton bPrevious;    private static JButton bNext;    private static JButton bEdit;    public JPanel getPanel() { return itemPanel; }    protected void setAndAdd(JComponent comp,        int gx, int gy, int gheight, int gwidth, double wx)    {	// to simplify laying out the gridbag	c.anchor = c.WEST;	c.gridx = gx; c.gridy = gy;	c.gridheight = gheight; c.gridwidth = gwidth;	c.weightx = wx;	gridbag.setConstraints(comp,c);	itemPanel.add(comp);    }    public MovieItemView()    {	myModel = (MovieModel)WmvcApp.getModel();	myModel.addView(this);		// adds update	// We will use a GridBag for simple layout of itemView	itemPanel = new JPanel();	// surrounding Panel	gridbag = new GridBagLayout();	c = new GridBagConstraints();	itemPanel.setLayout(gridbag);	itemPanel.setBorder(BorderFactory.createEmptyBorder(						5, 5, 5, 5));	// Set data fields to black foreground	fldTitle.setForeground(Color.black);	fldDirector.setForeground(Color.black);	fldYear.setForeground(Color.black);	fldRating.setForeground(Color.black);	fldGenre.setForeground(Color.black);	fldFormat.setForeground(Color.black);	fldLabel.setForeground(Color.black);	fldEvaluation.setForeground(Color.black);	// Movie Title: ________________________	setAndAdd(lblTitle, 0, 0, 1, 1, 1.0);	setAndAdd(fldTitle, 1, 0, 1, c.REMAINDER, 0.);	// Director: _____________________	setAndAdd(lblDirector, 0, 1, 1, 1, 1.0);	setAndAdd(fldDirector, 1, 1, 1, c.REMAINDER, 0.0);	// Year: _______      Genre: _________	setAndAdd(lblYear,  0, 2, 1, 1, 1.0);	setAndAdd(fldYear,  1, 2, 1, 1, 0.0);	setAndAdd(lblGenre, 2, 2, 1, c.RELATIVE,0.0);	setAndAdd(fldGenre, 3, 2, 1, c.REMAINDER,0.0);	// Rating: _______    Format: __________	setAndAdd(lblRating,  0, 3, 1, 1, 1.0);	setAndAdd(fldRating,  1, 3, 1, 1, 0.0);	setAndAdd(lblFormat,  2, 3, 1, c.RELATIVE, 0.0);	setAndAdd(fldFormat,  3, 3, 1, c.REMAINDER, 0.);	// My Rating: ______   Label: _________	setAndAdd(lblEvaluation,  0, 4, 1, 1, 1.0);	setAndAdd(fldEvaluation,  1, 4, 1, 1, 0.);	setAndAdd(lblLabel,     2, 4, 1, c.RELATIVE, 0.0);	setAndAdd(fldLabel,     3, 4, 1, c.REMAINDER, 0.);	// Comment box:	setAndAdd(lblComments,  0,5,1,1, 0.0);	textArea = new JTextArea(4,30);	JScrollPane textScroll = new JScrollPane(textArea);	setAndAdd(textScroll,  1,5,4,c.REMAINDER, 0.0);	// Command Buttons	bEdit =   new JButton("  Edit  ");	bEdit.setActionCommand("edit");	bEdit.addActionListener(this);	bEdit.setToolTipText("Edit current movie");	setAndAdd(bEdit, 1,9,1,1, 0.0);	bPrevious = new JButton("Previous");	bPrevious.addActionListener(this);	bPrevious.setActionCommand("previous");	bPrevious.setIcon(new ImageIcon("images/left-16.gif"));	bPrevious.setToolTipText("Go to previous movie");	setAndAdd(bPrevious, 2,9,1,1, 0.0);	bNext =     new JButton("Next");	bNext.setActionCommand("next");	bNext.addActionListener(this);	bNext.setIcon(new ImageIcon("images/right-16.gif"));	bNext.setToolTipText("Go to next movie");	setAndAdd(bNext, 3,9,1,1,0.0);    }    public void updateView()    {	// When model changes - update each fld componenet	Movie m = myModel.getCurrentMovie();	fldTitle.setText(m.getTitle());	fldDirector.setText(m.getDirector());	fldYear.setText(m.getYear());	fldLabel.setText(m.getLabel());	textArea.setText(m.getComments());	fldRating.setText(MovieRating.stringAt(m.getRating()));	fldGenre.setText(MovieGenre.stringAt(m.getGenre()));	fldFormat.setText(MovieFormat.stringAt(m.getFormat()));	fldEvaluation.setText(		MovieEvaluation.stringAt(m.getEvaluation()));    }    // Implement ActionListener    public void actionPerformed(ActionEvent e)    {	// Since only three buttons, easier to use one listener	if (e.getActionCommand().equals("edit"))	{	    Movie edited = 	    	MovieEditor.getInstance().showDialog(	    	   WmvcApp.getFrame(),	    	   myModel.getCurrentMovie());	    myModel.replaceCurrentMovie(edited);	}	else if (e.getActionCommand().equals("previous"))	{	    myModel.setCurrentMovieIndex(	         myModel.getCurrentMovieIndex()-1);	}	else if (e.getActionCommand().equals("next"))	{	    myModel.setCurrentMovieIndex(	         myModel.getCurrentMovieIndex()+1);	}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -