|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
ruby里有这些工具吗?又要简单多少?我没有用过这两门语言,我估计在这些语言力没有很统一的这种标准,或者根本就没有提供。
importjava.awt.BorderLayout;
importjava.awt.Color;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.JButton;
importjavax.swing.JEditorPane;
importjavax.swing.JPanel;
importjavax.swing.JScrollPane;
importjavax.swing.JTextPane;
importjavax.swing.UIManager;
importjavax.swing.WindowConstants;
importjavax.swing.text.AttributeSet;
importjavax.swing.text.DefaultStyledDocument;
importjavax.swing.text.Document;
importjavax.swing.text.EditorKit;
importjavax.swing.text.MutableAttributeSet;
importjavax.swing.text.SimpleAttributeSet;
importjavax.swing.text.StyleConstants;
importjavax.swing.text.StyledDocument;
importjavax.swing.text.StyledEditorKit;
publicclassNewJFrameextendsjavax.swing.JFrameimplementsActionListener{
privateJPaneljp1;
privateJButtoncolor;
privateJTextPanejep;
privateJScrollPanejsp;
privateJButtonfont;
/**
*Auto-generatedmainmethodtodisplaythisJFrame
*/
publicstaticvoidmain(String[]args){
NewJFrameinst=newNewJFrame();
inst.setVisible(true);
}
publicNewJFrame(){
super();
initGUI();
}
privatevoidinitGUI(){
try{
BorderLayoutthisLayout=newBorderLayout();
getContentPane().setLayout(thisLayout);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
jp1=newJPanel();
getContentPane().add(jp1,BorderLayout.NORTH);
{
font=newJButton();
font.addActionListener(this);
jp1.add(font);
font.setText("font");
}
{
color=newJButton();
jp1.add(color);
color.addActionListener(this);
color.setText("color");
}
}
{
jsp=newJScrollPane();
getContentPane().add(jsp,BorderLayout.CENTER);
{
jep=newJTextPane();
jsp.setViewportView(jep);
jep.setDocument(newDefaultStyledDocument());
}
}
pack();
setSize(400,300);
}catch(Exceptione){
e.printStackTrace();
}
}
publicstaticvoidsetFontSize(JEditorPaneeditor,intsize){
if(editor!=null){
if((size>0)&&(size<512)){
MutableAttributeSetattr=newSimpleAttributeSet();
StyleConstants.setFontSize(attr,size);
setCharacterAttributes(editor,attr,false);
}else{
UIManager.getLookAndFeel().provideErrorFeedback(editor);
}
}
}
publicstaticvoidsetForeground(JEditorPaneeditor,Colorfg){
if(editor!=null){
if(fg!=null){
MutableAttributeSetattr=newSimpleAttributeSet();
StyleConstants.setForeground(attr,fg);
setCharacterAttributes(editor,attr,false);
}else{
UIManager.getLookAndFeel().provideErrorFeedback(editor);
}
}
}
publicstaticfinalvoidsetCharacterAttributes(JEditorPaneeditor,
AttributeSetattr,booleanreplace){
intp0=editor.getSelectionStart();
intp1=editor.getSelectionEnd();
if(p0!=p1){
StyledDocumentdoc=getStyledDocument(editor);
doc.setCharacterAttributes(p0,p1-p0,attr,replace);
}
StyledEditorKitk=getStyledEditorKit(editor);
MutableAttributeSetinputAttributes=k.getInputAttributes();
if(replace){
inputAttributes.removeAttributes(inputAttributes);
}
inputAttributes.addAttributes(attr);
}
protectedstaticfinalStyledDocumentgetStyledDocument(JEditorPanee){
Documentd=e.getDocument();
if(dinstanceofStyledDocument){
return(StyledDocument)d;
}
thrownewIllegalArgumentException("documentmustbeStyledDocument");
}
protectedstaticfinalStyledEditorKitgetStyledEditorKit(JEditorPanee){
EditorKitk=e.getEditorKit();
if(kinstanceofStyledEditorKit){
return(StyledEditorKit)k;
}
thrownewIllegalArgumentException("EditorKitmustbeStyledEditorKit");
}
publicvoidactionPerformed(ActionEvente){
Objectobj=e.getSource();
if(obj==font){
JEditorPaneeditor=jep;
setFontSize(editor,20);
}
if(obj==color){
JEditorPaneeditor=jep;
setForeground(editor,Color.red);
}
}
}
<p>
有了这样一个呼声:让java代替C语言成为基本语言。这些足以说明java简单易学的这个优点。其次,java的功能强大,前面我也提到了,EJB3.0的推出使java成为了大型项目的首选。 |
|