81,092
社区成员
发帖
与我相关
我的任务
分享
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
//*********Found**********
public class Java_3 extends ______________________ implements ActionListener
{
//*********Found**********
private ____________________ pop;
private JMenu subPop;
private JMenuItem color;
private JMenuItem exit;
private JMenuItem red;
private JMenuItem blue;
private JTextArea textArea;
private JFrame frame;
public void initGUI()
{
pop=new JPopupMenu();
subPop=new JMenu("color");
//*********Found**********
red=new JMenuItem("______________________");
red.addActionListener(this);
blue=new JMenuItem("blue");
blue.addActionListener(this);
subPop.add(red);
subPop.add(blue);
exit=new JMenuItem("exit");
exit.addActionListener(this);
pop.add(subPop);
pop.add(exit);
frame=new JFrame("popup frame");
textArea=new JTextArea("",10,10);
textArea.addMouseListener(this);
//*********Found**********
frame.getContentPane().add(____________________);
frame.setSize(300,300);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent event)
{
if(event.getSource()==red)
{
//*********Found**********
textArea.setForeground(Color._____________________);
textArea.setText("red menu is selected");
}
else if(event.getSource()==blue)
{
textArea.setForeground(Color.blue);
textArea.setText("blue menu is selected");
}
else if(event.getSource()==exit)
{
frame.setVisible(false);
System.exit(0);
}
}
public void mousePressed(MouseEvent e)
{
if(e.getModifiers()==e.BUTTON3_MASK)
{
pop.show(e.getComponent(),e.getX(),e.getY());
}
}
public static void main(String args[])
{
Java_3 example=new Java_3();
example.initGUI();
}
}
import java.awt.event.*;
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import javax.swing.*;
public class Java_3
{
public static void main(String[] args)
{
FontFrame frame = new FontFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
//**********Found**********
class FontFrame extends ________________
{
public FontFrame()
{
setTitle("北京 2008");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
FontPanel panel = new FontPanel();
Container contentPane = getContentPane();
//**********Found**********
contentPane.add(_____________________);
}
public static final int DEFAULT_WIDTH = 400;
public static final int DEFAULT_HEIGHT = 250;
}
class FontPanel extends JPanel
{
public FontPanel()
{
JButton yellowButton = new JButton("Yellow");
JButton blueButton = new JButton("Blue");
JButton redButton = new JButton("Green");
add(yellowButton);
add(blueButton);
add(redButton);
ColorAction yellowAction = new ColorAction(Color.YELLOW);
ColorAction blueAction = new ColorAction(Color.BLUE);
ColorAction greenAction = new ColorAction(Color.GREEN);
yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(blueAction);
redButton.addActionListener(greenAction);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
String message = "同一个世界,同一个梦想!";
Font f = new Font("隶书", Font.BOLD, 27);
g2.setFont(f);
FontRenderContext context = g2.getFontRenderContext();
Rectangle2D bounds = f.getStringBounds(message, context);
double x = (getWidth() - bounds.getWidth()) / 2;
double y = (getHeight() - bounds.getHeight()) / 2;
double ascent = -bounds.getY();
double baseY = y + ascent;
g2.setPaint(Color.RED);
g2.drawString (message, (int)x, (int)(baseY));
}
//**********Found**********
private class ColorAction ____________________ ActionListener
{
public ColorAction(Color c)
{
BackgroundColor = c;
}
//**********Found**********
public void _____________________ (ActionEvent event)
{
setBackground(BackgroundColor);
}
private Color BackgroundColor;
}
}
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class Java_3
{
public static void main(String[] args)
{
JFrame frame = new ImageViewerFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class ImageViewerFrame extends JFrame
{
public ImageViewerFrame()
{
setTitle("ImageViewer");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
label = new JLabel();
Container contentPane = getContentPane();
contentPane.add(label,BorderLayout.CENTER);
chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu menu = new JMenu("File");
menuBar.add(menu);
JMenuItem openItem = new JMenuItem("Open");
//*********Found**********
_______________.add(openItem);
//*********Found**********
openItem.___________________________(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
int r = chooser.showOpenDialog(null);
if(r == JFileChooser.APPROVE_OPTION)
{
//*********Found**********
String name = __________________.getSelectedFile().getPath();
label.setIcon(new ImageIcon(name));
}
}
});
labelT = new JLabel("红军不怕远征难");
labelT.setFont(new Font("隶书", Font.PLAIN, DEFAULT_SIZE));
contentPane.add(labelT, BorderLayout.NORTH );
faceCombo = new JComboBox();
faceCombo.setEditable(true);
faceCombo.addItem("隶书");
faceCombo.addItem("华文新魏");
faceCombo.addItem("华文行楷");
faceCombo.addItem("华文隶书");
//*********Found**********
faceCombo.________________________(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
//*********Found**********
labelT.setFont(new Font((String)____________________.getSelectedItem(),
Font.PLAIN, DEFAULT_SIZE));
}
});
JPanel comboPanel = new JPanel();
comboPanel.add(faceCombo);
contentPane.add(comboPanel, BorderLayout.SOUTH);
}
private JLabel label;
private JLabel labelT;
private JFileChooser chooser;
private JComboBox faceCombo;
private static final int DEFAULT_SIZE = 24;
public static final int DEFAULT_WIDTH = 570;
public static final int DEFAULT_HEIGHT = 400;
}
public class Java_1
{
public static void main(String[] args)
{
long sum;
//*********Found**********
___________________;
for(int i=1;i<8;i+=2){
long b=1;
//*********Found**********
for(int j=1; j<=___________; j++)
//*********Found**********
__________________;
System.out.println( i + "!= " + b);
sum+=b;
}
System.out.println("sum=" + sum);
}
}