|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
没有那个大公司会傻了吧唧用.net网页编程开发大型项目,开发了,那等于自己一半的生命线被微软握着呢。而.net网页编程不行,限制在window系统,又是捆绑,鄙视微软之!- //packagetryLineNumber;
- importjava.awt.BorderLayout;
- importjava.awt.Dimension;
- importjava.awt.Graphics;
- importjava.awt.Point;
- importjavax.swing.JFrame;
- importjavax.swing.JTextArea;
- importjavax.swing.JPanel;
- importjavax.swing.JScrollPane;
- //importjavax.swing.JTextPane;
- importjavax.swing.text.BadLocationException;
- importjavax.swing.text.Document;
- /**
- *AclassillustratingrunninglinenumbercountonJTextPane.Nothing
- ispaintedonthepaneitself,
- *butaseparateJPanelhandlespaintingthelinenumbers.
- *
- *@authorDanielSj?blom
- *CreatedonMar3,2004
- *Copyright(c)2004
- *@version1.0
- */
- publicclassLineNrextendsJPanel
- {
- //forthissimpleexperiment,wekeepthepane+scrollpaneasmembers.
- //JTextPanepane;
- JTextAreapane;
- JScrollPanescrollPane;
- publicLineNr()
- {
- super();
- setMinimumSize(newDimension(30,30));
- setPreferredSize(newDimension(30,30));
- setMinimumSize(newDimension(30,30));
- //pane=newJTextPane()//weneedtooverridepaintsothatthelinenumbersstayinsync
- pane=newJTextArea()
- {
- publicvoidpaint(Graphicsg)
- {
- super.paint(g);
- LineNr.this.repaint();
- }
- };
- scrollPane=newJScrollPane(pane);
- }
- publicvoidpaint(Graphicsg)
- {
- super.paint(g);
- //Weneedtoproperlyconvertthepointstomatchtheviewport
- //Readdocsforviewport
- intstart=pane.viewToModel(scrollPane.getViewport().getViewPosition());//startingposindocument
- intend=
- pane.viewToModel(
- newPoint(
- scrollPane.getViewport().getViewPosition().x+pane.getWidth(),
- scrollPane.getViewport().getViewPosition().y+pane.getHeight()));
- //endposindoc
- //translateoffsetstolines
- Documentdoc=pane.getDocument();
- intstartline=doc.getDefaultRootElement().getElementIndex(start)+1;
- intendline=doc.getDefaultRootElement().getElementIndex(end)+1;
- intfontHeight=g.getFontMetrics(pane.getFont()).getHeight();
- intfontDesc=g.getFontMetrics(pane.getFont()).getDescent();
- intstarting_y=-1;
- try
- {
- starting_y=pane.modelToView(start).y-
- scrollPane.getViewport().getViewPosition().y+fontHeight-fontDesc;
- }
- catch(BadLocationExceptione1)
- {
- e1.printStackTrace();
- }
- for(intline=startline,y=starting_y;line<=endline;y+=fontHeight,line++)
- {
- g.drawString(Integer.toString(line),0,y);
- }
- }
- //testmain
- publicstaticvoidmain(String[]args)
- {
- JFrameframe=newJFrame();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(newBorderLayout());
- finalLineNrnr=newLineNr();
- frame.getContentPane().add(nr,BorderLayout.WEST);
- frame.getContentPane().add(nr.scrollPane,BorderLayout.CENTER);
- frame.pack();
- frame.setSize(newDimension(400,400));
- frame.show();
- }
- }
复制代码 多谢指点,其实我对.net网页编程和ruby也不是很了解,对与java也只是刚起步的阶段,只是在学习中有了点想法就写出来了,现在俺本科还没毕业,所以对大型项目基本上也没有什么经验。 |
|